Hi All, I am working on basic spring and hibernate application.I am using createCriteria() methods for retrieving data from database.But I have removed transaction methods (like beginTransaction() or commit).Is it possible to use criteriaQueries without transaction methods ? I understand that I can achieve this using spring transaction.But I want to do it in Hibernate.Can anyone clarify this for me ? Thanks in advance.
With JPA/Hibernate (mainly with Sprng Data JPA packages), the @EntiityManager is by default at the transaction scope, and if the transaction has multiple threads, then it is at the thread scope. The scope can be expanded with some EM options. Google the use of EM, EM Factory, etc.
So createCriteria (CriteriaBuilder, CriteriaQuery, Root) should work. I think you mainly need to set your persistence.xml, PersistenceContext, EM Factory (should be a singleton) and EM (should be per transaction/thread) correctly. You don't want to set the transaction boundaries manually.
SCJP 1.4, SCWCD, SCBCD 1.3
Honk if you love justice! And honk twice for tiny ads!
Free, earth friendly heat - from the CodeRanch trailboss