tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Blevins <david.blev...@visi.com>
Subject Re: PersistenceContext and Hibernate session
Date Fri, 11 Jul 2008 20:17:38 GMT
Hi Olivier,

This document may help you understand how things work from a high level.

   http://cwiki.apache.org/OPENEJBx30/jpa-concepts.html

The section of bullet points for "With <persistence-unit transaction- 
type="TRANSACTION">" has a good description of what's going on.  When  
reading it, in your mind substitute every occurrence of  
"PersistenceContext/Cache" with "HibernateEntityManager instance".

-David

On Jul 11, 2008, at 8:55 AM, Dain Sundstrom wrote:

> 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