@Unique 在带有 NeoDatis 的 DataNucleus 中没有任何效果

发布于 2024-10-01 11:00:28 字数 298 浏览 1 评论 0原文

使用 JDO / DataNucleus / NeoDatis 数据存储,

我将 @Unique 添加到可持久对象的字段中,但是我可以创建多个违反唯一约束的对象。 DataNucleus/NeoDatis 的文档建议支持唯一字段。

@PersistenceCapable
public class User {
 @Persistent
 @Unique
 private String username;
 //...
}

如果我使用相同的用户名将多个对象添加到数据库中,那么这样做是没有问题的。

Using JDO / DataNucleus / NeoDatis datastore

I added @Unique to a field of a persistable object, however I am allowed to create multiple objects which violate the unique constraint. The docs for DataNucleus/NeoDatis suggest that Unique fields are supported.

@PersistenceCapable
public class User {
 @Persistent
 @Unique
 private String username;
 //...
}

If I add multiple objects to the DB with the same username there's no problem doing so.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

苍暮颜 2024-10-08 11:00:28

您是否为唯一约束指定了名称?

@Unique(name="USERNAME_IDX")
private String username;

Did you specify a name for your unique constraint ?

@Unique(name="USERNAME_IDX")
private String username;
故事灯 2024-10-08 11:00:28

NeoDatis 的 DataNucleus 实现似乎不支持唯一属性。在 NeoDatis 中,它要求您在字段上添加唯一索引(请参阅下面描述这一点的 NeoDatis 论坛的链接)。

http://sourceforge.net/projects/neodatis-odb/forums /forum/619814/topic/3409305

It appears that the DataNucleus implementation for NeoDatis doesn't support unique attributes. In NeoDatis it requires that you add a unique index on the field (see link below for NeoDatis forums describing this).

http://sourceforge.net/projects/neodatis-odb/forums/forum/619814/topic/3409305

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文