Property Tag in Hibernate Mapping by R4R Team

Property in Hibernate Mapping: 







formula="arbitrary SQL expression"







node="element-name|@attribute-name|element/@attribute|." index="index_name" unique_key="unique_key_id" length="L" precision="P" scale="S" 





In the property tag we use the name for the using the name of the property with an initial lowercase letter


We see the this defaults as property name.

Name of the mapped database table column. This can also be specified by nested <column> elements


This name indicate the hibernate type.


We found this on defaults true.

This specifies that the mapped columns should be included in SQL UPDATE and INSERT statements. We set both to false allows a pure “derived” property whose value is initialized from some other property that maps to the same column or we can say it by a trigger of other application.


In hibernate an sql expression that defines the value for a computed property. We found the computed property do not have a column mapping of their own.


It set on by defaults to property.

It show the strategy hibernate uses for accessing the property value.


It set to defaults false.

It specifies that this property should be fetched lazily when the instances variable is first accessed. It requires build-time bytecode instrumentation.


It enable the DDL generation of a unique constraint for the column so we allows this to be the target of a property set.


It enables the DDL generation of a nullability constraint for the columns.


It found by defaults on true.

It specifies that updates to this property do or do not require acquisition of the optimistic lock. We can say in other word, it determines if a version increment shold occur when this property is dirty.


It can't set by defaults never.

It specifies that this propety value is actually generated by the database.

we have some property that is given below:

1. Hibernate basic type: integer,string,character,date,timestamp,float,binary,serializable,object,blob.
2. Java class with a default basic type: int, float, char, java.lang.String, java.util.Date, java.util.Integer, java.sql.Clob.
3. Serializable Java class.
4. Some class name of custom type: com.illflow.type.MyCustomType

when we specify a type, In hibernate will use reflection upon the named property and guess the correct Hibernate type. Hibernate will attempt to interpret the name of the return class of the property  with getter using, in order, rules 2, 3, and 4. In certain cases need the type attribute. 

For example, Distinguish between Hibernate.DATE and Hibernate.TIMESTAMP, or to specify a custom type.

The access attribute allows you to control how Hibernate accesses the property at runtime. By default, Hibernate will call the property get/set pair. If specify access="field", Hibernate will bypass the get/set pair and access the field directly using reflection. You can specify your own strategy for property access by naming a class that implements the interface

A powerful feature is derived properties. These properties are by definition read-only. The property value is computed at load time. You declare the computation as an SQL expression. This then translates to a SELECT clause subquery in the SQL query that loads an instance:

formula="( SELECT SUM (li.quantity*p.price) FROM LineItem li, Product p WHERE li.productId = p.productId AND li.customerId = customerId AND li.orderNumber = orderNumber )"

Can reference the entity table by not declaring an alias on a particular column. This would be customerId in the given example. You can also use the nested <formula> mapping element if you do not want to use the attribute.return
Leave a Comment:
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on 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!