tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dain Sundstrom <d...@iq80.com>
Subject Re: PersistenceContext and Hibernate session
Date Fri, 11 Jul 2008 15:55:55 GMT
JtaEntityManager is a wrapper around the raw EntityManager instance we  
get from the JPA provider.  JtaEntityManager performs the task  
required by the EJB spec such as committing the flushing the JPA data  
at the end of the transaction and assuring that all access to the same  
persistence unit in a transaction uses the same raw EntityManager.   
You can get access to the raw underlying EntityManager by calling  
getDelegate(), but be careful.  You should not cache the results of  
getDelegate() as the raw EntityManager instance will change for each  
transaction.  You'll want to do something like this:

     @javax.persistence.PersistenceContext(unitName = "t4Seam")
     protected javax.persistence.EntityManager emanager;

     public HibernateEntityManager getHibernateSession() {
         return (HibernateEntityManager) emanager.getDelegate();
     }

     public void doIt() {
         getHibernateSession().doSomething();
     }

-dain

On Jul 11, 2008, at 8:09 AM, chawax wrote:

>
> I tried this :
>
>    protected org.hibernate.ejb.HibernateEntityManager emanager;
>
>    @javax.persistence.PersistenceContext(unitName = "t4Seam")
>    public void setEntityManager(javax.persistence.EntityManager
> entityManager) {
>    	this.emanager = (org.hibernate.ejb.HibernateEntityManager)
> entityManager;
>    }
>
> But I have a ClassCastException :
>
>    java.lang.ClassCastException:
> org.apache.openejb.persistence.JtaEntityManager
>
> Is there a place where I could configure the entity manager to use  
> Hibernate
> one instead of OpenEJB one ?
> -- 
> View this message in context: http://www.nabble.com/PersistenceContext-and-Hibernate-session-tp18404318p18406052.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>


Mime
View raw message