Saturday, 24 December 2022

Hibernate 6: Composite identifiers

Entity identifiers are used to uniquely identify a row in a table. Hibernate and JPA (Jakarta Persistence API), assumes following rules must be followed by the identifier.

 

a.   Identifier must be unique in a table.

b.   Identifier must not be null. If you use a composite key as an identifier, then no other part can be null.

c.    Once a value assigned to identifier property, the value must not be changed on any circumstances.

 

Types of identifiers

An identifier can be

a.   Simple

b.   Composite

 

Let’s discuss about composite identifiers in this post. Composite identifier is formed by combining more than one persistent attribute.

 

Hibernate support below approaches to model an entity with composite identifier.

a.   Composite identifiers with @EmbeddedId

b.   Composite identifiers with @IdClass

c.    Composite identifiers with associations

d.   Composite identifiers with generated properties

Previous                                                    Next                                                    Home

No comments:

Post a Comment