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 Wed, 16 Jul 2008 03:27:38 GMT
On Jul 15, 2008, at 2:32 PM, David Blevins wrote:

> On Jul 15, 2008, at 6:11 AM, chawax wrote:
>
>>
>> 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.
>
> Congrats, glad you got it to work in both platforms!
>
>> 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 ?
>
> The spec simply says "The result of this method is implementation  
> specific."  So either version is valid strictly speaking.
>
> On that note, we could add a flag that would have our getDelegate()  
> detect if it's hibernate and return the hibernate session if that  
> would make your life easier.

It would be cool if we could just support org.hibernate.Session as a  
recognized injection type.  Then anyone using code similar to the  
original code posted would just work.

-dain

Mime
View raw message