开发者

@Unique doesn't have any effect in DataNucleus w/ NeoDatis

开发者 https://www.devze.com 2023-01-23 22:59 出处:网络
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 Data

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 user开发者_如何学JAVAname there's no problem doing so.


Did you specify a name for your unique constraint ?

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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号