Use of \"Any\" Property in Hibernate by R4R Team

Use of "Any" Property in Hibernate: In hibernate we found the one more type of property mapping that is the <any>. It mapping defines a polymorphic association to classes from multiple tables. This type of mapping requires in the database table more than one table. In that type of table first column contain the type of associated entity and the remaining column contain the identified. In the database it is imposible to specify the foreign key constraint for this kind of association. We see that this is not usual way of mapping polymorphic association and then we need to use this only in special cases.


for understanding the above discussion we take a small example that is given below:


It works for audit logs, user session data etc,


The meta type attribute allows the application to specify a custom type maps database column values to persistent classes that have identifier properties of the type specified by id-type. So for this we need to specify the mapping from values of the meta -type to class names.


<any name="being" id-type="long" meta-type="string"> 

<meta-value value="TBL_Machine" class="Machine"/> 

<meta-value value="TBL_Person" class="Person"/> 

<meta-value value="TBL_Ror" class="Ror"/> 

<column name="table_name"/> <column name="id"/> 

</any>


<any name="propertyName" id-type="idtypename" meta-type="metatypename" cascade="cascade_style" access="field|property|ClassName" optimistic-lock="true|false" > <meta-value ... /> <meta-value ... /> ..... <column .... /> <column .... /> ..... </any>


So for this we given belwo the small description below:


Tag

Description

name

It shows the property name.

id-type(optional)

It shows the identifier type.

meta-type(optional)

We see this defaults on the string.

In this any type that is allowed for a discriminator mapping.

cascade(optional)

It shows the cascade style.

access(optional)

It found defaults to the property.

It shows the strategy of hibernate uses for a accessing the property value.

optimistic-lock(optional)

It found on the property by defaults.

It specifies that updates to this property either do or do not require acquisition of the optimistic lock. It defines whether a version increment should occur if this property is dirty.

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!