Question

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.

Was it helpful?

Solution 2

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

OTHER TIPS

Did you specify a name for your unique constraint ?

@Unique(name="USERNAME_IDX")
private String username;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top