Is this the right way to use createCriteria with entityManager ?
Code:
import javax.persistence.*;
import org.hibernate.ejb.HibernateEntityManager;
private javax.persistence.EntityManagerFactory emf;
ClassName(){
emf= javax.persistence.Persistence.createEntityManagerFactory("PERSISTENCE_UNIT_TEST");
}
public Collection getSomething(){
EntityManager em = emf.createEntityManager();
try {
em.getTransaction().begin();
org.hibernate.Session session = ((HibernateEntityManager)em).getSession(); //is this line correct ????
// do i need to close the session at the end ?
// or em.close will auto-close the session????
List resultCol = session.createCriteria(MyPOJO.class);
em.getTransaction().commit();
return resultCol;
} catch (Exception e) {
theLogger.log(Level.SEVERE,"dao error",e);
em.getTransaction().rollback();
} finally {
em.close();
}
return null;
}