ObjectDB ObjectDB

@Unique added afterward is not taken into account



I encounter an issue with the @Unique annotation. The annotation was added on a given field itemID (String), important point : the annotation was added afterwards (after objects were already added to the table). As a consequence the unique constraint is not taken into account when persisting an object which itemID is already present no error is thrown at commit, the object is just added to the table. It is a problem as we rely on the commit error to know when adding or updating object in table. This error was previously encountered in similar conditions with another table, it was solved only after recreating a blank table and adding all entities one by one in it (so using the new scheme for all entities).

So the question is simple, is there a better way to "re-activate" the @Unique constraint on all object already present in the table, including those made before annotation was added?

Thank you.


Unique is implemented as an index, and adding an index on existing data requires rebuilding the database by using the Doctor in repair mode (a better support for adding a new index is expected to be released soon).

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)

OK perfect, thank you..



To post on this website please sign in.