n+1 selects problem:
The biggest performance killer in applications that persist objects to SQL databases is the n+1 selects problem. For this map all the associations for lazy initialization, this means lazy="true" and fetch="join" ( this is default in Hibernate 3 ).
Use HQL LEFT JOIN FETCH to specify which associations you need to be retrieved in the initial SQL SELECT.
This is the only way to avoid retrieving all objects in the database in every transaction.
More about declaring and defining primary keys in mapping definition file:
For a primary key column
<id name="id" type="long" column="ID" >
<generator class="native"/> // there are several other types of this class ( for ex: sequence, increment, etc )
</id>
For a composite primary key
<composite-id>
<key-property name="deptId" type="string" column="DEPT_ID" />
<key-property name="IdCardNo" type="string" column="ID_CARD_NO"/>
</composite-id>
Ten reasons to love Hibernate
1.Dynamic UPDATE generation – figure out which columns changed
2.Trying new databases
3.Traversing associations
4.Optimistic Locking
5.ID generation
6.No more DTOs
7.Query result paging
8.Automatic dirty checking
9.Good price - free to use it.
10.Good documentation
The five core interfaces are used in just about every Hibernate application. Using these interfaces, you can store and retrieve persistent objects and control transactions.
* Session interface
* SessionFactory interface
* Configuration interface
* Transaction interface
* Query and Criteria interfaces
What is Hibernate proxy?
The proxy attribute enables lazy initialization of persistent instances of the class. Hibernate will initially return CGLIB proxies which implement the named interface. The actual persistent object will be loaded when a method of the proxy is invoked.
About Hibernate-reveng configuration file
An eclipse plugin used to generate the hibernate mapping files (.hbm).
Levels of Caching
First Level:
This is at the session scope level.
Second Level:
The first step is to choose a cache provider. EHCache, which is the default cache provider for Hibernate.
You can as well Cache queries:
If you are running the same query in two different sessions,
for ex:
<hibernate-configuration>
<session-factory>
...
<property name="cache.use_query_cache">true</property>
...
</session-factory>
</hibernate-configuration>