Aadi Droid
Aadi Droid

Reputation: 1739

Hibernate Annotations Id for table with no primary key

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.

Upvotes: 4

Views: 8395

Answers (1)

Reddy
Reddy

Reputation: 8911

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

Upvotes: 1

Related Questions