In order to work with the unique constraints you will need to remember the following 3 steps.
1. Add an index for a field you wish to be unique:
Java:
configuration.objectClass(Item.class).objectField("field").indexed(true);
Java:
configuration.add(new UniqueFieldValueConstraint(Item.class,
"field"));
Java:
// open objectContainer
try {
// do some work and save some objects
objectContainer.commit();
} catch(UniqueFieldValueConstraintViolationException ex) {
// log the error, notify the
user
objectContainer.rollback();
}