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 Tue, 15 Jul 2008 21:32:12 GMT

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.

-David


Mime
View raw message