FAQ
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.

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 8 of 10 | next ›
Discussion Overview
groupusers @
categoriesopenejb
postedJul 11, '08 at 1:50p
activeJul 16, '08 at 3:28a
posts10
users4
websiteopenejb.apache.org
irc#openejb

People

Translate

site design / logo © 2021 Grokbase