Once you execute following code:
Criteria criteria = detachedCriteria
you cannot reause the detachedCriteria for creating another one executable criteria because they are connected together (e.g. setting projection or pagination for criteria modifies also detachedCriteria object).
You must do following workarounds:
detachedCriteria.setResultTransformer( Criteria.ROOT_ENTITY );
detachedCriteria.setProjection( null );
For more info see Hibernate forum –
I would recommend you to read Real-World Experiences With Hibernate at www.shinetech.com. The best article about Hibernate I have read.
I got involved in new project in Janury. The goal was to develop new version of existing application. It must be 2tier RCP and it must be albe work over many databases (used by 16 banks, political reasons).
We decided to use Eclipse RCP and Hibernate.
Eclipse RCP work’s fine. SWT and JFace makes gui development quite easy.
But using Hibernate in 2tier application brings many difficulties:
- Session slows down when contains many (hundreds) objects
- You cannot use Session after you got some error on it
- There are some bugs in HQL that make advanced usage quite difficult
See Hibernate in 2 tier application discussiong Is it Possible to Combine Hibernate + Swing?????.
After 5 months (I became the project leader meanwhile) we eneded up with 2,5 tier design:
- use DAO classes to load light objects displayed in views (eg. load, initialize and close session in getChildren methods)
- use SQL and HQL for batch updates where possible
- use session per editor, load with LockMode.UPGRADE
- use Maps instead of querying database
- divide batch processing into small part, each in new session and transaction or use StateLess session
Advanced Hibernate bugs
- HQL delete in 3.1.3 bug (we use version 3.1.2)
- HQL insert into … select … statement problem due to lacking table aliases in select clause (we use sql directly)
- HQL update on classes using inheritance requires temporary tables when not necessary
PS: next version must be 3-tier application.