-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: the right way to use createCriteria with EntityManager
PostPosted: Tue Sep 09, 2008 1:29 pm 
Newbie

Joined: Sat Aug 23, 2008 9:10 am
Posts: 5
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;

}



           






Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.