Hibernate @Id and Oracle Single constraint


Can I use a hibernate entity with @Id on a single constraint instead of a primary key on Oracle databases? Will this be JPA compliant?

The answer

This sounds a little strange, but seems possible:

The field or property to which the ID annotation is applied must be one of the following types : any Java primitive type; any type of primitive envelope; Chain; java.util.Date; java.sql.Date; java.math.BigDecimal; java.math.BigInteger.

But be aware:
(1) For example, in Oracle UNIQUE does NOT imply NOT NULL, you must make sure of your choice.
(2) You can not use a FOREIGN KEY constraint in your database.
(3) You need to be careful with Id generation (http://www.objectdb.com/api/java/jpa/GeneratedValue) if you want to insert new entities (not only read existing ones).
(4) If you insert a new entity, you must generate a value for the database ID.

And these are just a few inconveniences that have come to mind quickly ...

Related articles

SQL Single constraint on multiple tables


I'm trying to create a single constraint on multiple tables. I have found answers to similar questions here, but they do not quite reflect the spirit of what I am trying to do. As an example, I have three tables, t_Analog, t_Discrete, t_Message CREAT

Oracle - ignoring constraint failures


I have a "personal" table with many lines, and I would like to remove the unused rows from this table (all employees who have never been referenced by another table). There are constraints such that it is not possible to delete rows from the per

PostgreSQL error, no matching single constraint


When trying to create a database that allows a course to have multiple sections, and a section to have multiple events / periods as to when they meet. Everything is linked correctly, but I have a problem with a PostgreSQL error, which allows me to te