tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chawax <olivier.thie...@gmail.com>
Subject Re: PersistenceContext and Hibernate session
Date Tue, 15 Jul 2008 13:11:22 GMT

I finally could make it work with JBoss AS ... but it doesn't work the same
as Open EJB !
On JBoss AS the getDelegate method returns Hibernate session, while it
returns Hibernate entity manager on Open EJB. So to make it work, I made
this :

    protected javax.persistence.EntityManager emanager;

    protected org.hibernate.Session hibernateSession;

    @javax.persistence.PersistenceContext(unitName = "t4Seam")
    public void setEntityManager(javax.persistence.EntityManager
entityManager) {
    	this.emanager = entityManager;
    	if (entityManager.getDelegate() instanceof
org.hibernate.ejb.HibernateEntityManager) {
    		this.hibernateSession = ((org.hibernate.ejb.HibernateEntityManager)
entityManager.getDelegate()).getSession();
    	}
    	else {
    		this.hibernateSession = (org.hibernate.Session)
entityManager.getDelegate();
    	}
    }

So I have a question : which one is right with this, Open EJB or JBoss AS ?
Or maybe the JPA specifications are not clear about this, so there can be
different implementations for this method ?

-Olivier



chawax wrote:
> 
> Thanks Dain, your suggestion worked perfect with OpenEJB.
> 
> But it doesn't work with JBoss AS 4.2.x. I have this error :
> java.lang.ClassCastException: org.hibernate.impl.SessionImpl
> 
> Anyway, that's not an Open EJB issue, so I will ask on Hibernate or JBoss
> forums.
> 
> Thanks.
> 
> -Olivier
> 
> 
> Dain Sundstrom wrote:
>> 
>> 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
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/PersistenceContext-and-Hibernate-session-tp18404318p18464923.html
Sent from the OpenEJB User mailing list archive at Nabble.com.


Mime
View raw message