Natural-id in Hibernate by R4R Team

Here in Hibernate we use surrogate key as the primary key, so we need to try to identify natural key for all entities. This means a natural key is a property or combination of properties that is unique and not null. So it is also immutable and Map the properties of the natural key inside the <natural-id> element. Hibernate will generate the necessary unique key and nullability constraints and as a result than mapping will be more self-documenting.In Hibernate it is also recomended that implement equals() and hashCode() to compare the natural key properties of the entity.We can say that to this mapping is not intended for use with entities that have natural primary key.


<natural-id mutable="true|false"/> <property ... /> <many-to-one ... /> ...... </natural-id>


It has only one property that is given below:


1. mutable(optional): This is set by defaults false and natural identifier properties are assumed to be immutable(constant)

Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!