What’s new?

Rework of the Component Chapter
- update from CollectionOfElements to ElementCollection (the former is now deprecated)
- better explanation why and when you need to implement equals and hashcode in component collections

Rework of native SQL Chapter
Some times you need to get full access to database specific features. In those cases you need plain SQL.
But did you know that Hibernate can create entities from SQL queries? The chapter has been significantly enlarged and covers SQLResultSetMappings as well.

Query chapter
I have added some examples to query for example authors having two books in their collection. Hibernate provides a number of short cut functions to avoid subquery:
element, size, member of.

Access to JDBC is explained now in detail

Session.lock
session.lock is now deprecated. You will find the new approach session.buildLockRequest in the book.

Cascading
Cascading has slightly changed considering so-called orphan-removal. This is now supported by JPA as well and the Hibernate cascade type is deprecated.

ResultTransformer
If you query an object for example a book and join a collection of chapters, you will find duplicates in the result list. The preferred way to prevent this, is setting a result transformer.
session.createQuery(..).setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)

There are other result transformer you may use, when writing reporting queries.


Best Regards / Viele Grüße

Sebastian Hennebrueder