We are developing a Java EE application using Hibernate as a JPA provider. We now wish to use Hibernate Criterias but for that I need to get access to the HibernateEntityManagerImpl.
We have this currently in our componentContext.xml
<context:component-scan base-package="com.volvo.it.lsm"/>
<!-- JPA EntityManagerFactory -->
<bean id="EmployeeDomainEntityManagerFactory" parent="hibernateEntityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="EmployeeDomainPU" />
</bean>
and in our classes:
@PersistenceContext(unitName = "EmployeeDomainPU")
public void setEntityManager(EntityManager em) {
this.em = em;
}
Thanks!
Use this code:
Note that JPA2 has a (different) Criteria API as well. It’s harder to use IMHO, but it’s more type-safe, and has the same advantages as the Hibernate Criteria API (be able to dynamically compose a query)