Properties Tag in Hibernate by R4R Team

Properties Tag in Hibernate: Hibenate has a different kind of operation for that required the some basic tag to do that operation. In this list we found the property tag. <properties> permissed to allow to the element definition with name,logical grouping of the properties of a class. The most important use of this is to construct and allows a combination of properties to be target of a property-ref. It is also convenient way to define a multi-column unique constraint.


We can take a simple example for this to understand which is given below:


<properties 

name="logicalName"

insert="true|false"

update="true|false"

optimistic-lock="true|false"

unique="true|false"> 

<property ...../> <many-to-one .... /> ........ </properties>


To understand the below code of example we have given a small description of each point:


Property Name

Description

name

It is a logical name of the grouping. It is not an actual property name.

insert

With the help of this we can do the mapped column appear in SQL INSERT

update

With the help of this we can do the mapped column appear in SQL UPDATE

optimistic-lock(optional)

It specifies that updates to these properties either do or do not require acquistion of the optimistic lock. It determines if a version increment should occur whrn these properties are dirty.

unique(otional)

It found on the by defaults false.

It specifies that a unique constraint exists upon all maped columns of the componant.


We can take a another example of this:

<class name="Student"> <id name="StudentNumber"/> ... <properties name="name" unique="true" update="false"> <property name="firstName"/> <property name="initial"/> <property name="lastName"/> </properties> </class>

Having some legacy data association that refers to this unique key of the Student table, instead of to the primary key:

<many-to-one name="Student" class="Student" property-ref="name"> <column name="firstName"/> <column name="initial"/> <column name="lastName"/> </many-to-one>

The use of this outside the context of mapping legacy data is not recommended.
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!