Hibernate Annotations Id for table with no primary key

Aadi Droid picture Aadi Droid · Jun 28, 2012 · Viewed 7.5k times · Source

I have a table that has no primary key, and one cannot be created either. I can construct a unique key using three columns of this table. Now hibernate demands an id for every annotated class, how do i satisfy this id with the unique Id I can create.

Answer

Reddy picture Reddy · Jun 28, 2012

If it is an entity type then you should use a composite key. This can be done by moving primary key fields to separate class and mapping that in entity class with an @Id annotation.

See Mapping composite primary keys and foreign keys to composite primary keys

If it is not an entity but a value type you should map it accordingly. See https://stackoverflow.com/a/1696146/324900 and Entity and value types in hibernate