Hi,
From the documentation I seems that I should be able get access to the session of container managed entity manager.
http://www.hibernate.org/hib_docs/entit ... cture.html
So I would like to try this in my EJB3 app on JBoss 4.2. So now I have a Session bean with
Code:
@PersistenceContext(unitName = "tacs") @Inject EntityManager entityManager;
[...]
public void test(Cpe cpe){
System.out.println("Transaction in EJB " + entityManager.getDelegate().hashCode() );
cpe.getMatch();
}
and Cpe has
Code:
public static EntityManagerFactory getEntityManagerFactory() {
EntityManagerFactory entityManagerFactory = null;
try {
entityManagerFactory = (EntityManagerFactory)(new InitialContext()).lookup("java:/tacsEntityManagerFactory");
} catch(NamingException e) { }
return entityManagerFactory;
}
public static Session getSession(){
EntityManager entityManager = getEntityManagerFactory().createEntityManager();
return (org.hibernate.Session) entityManager.getDelegate();
}
public void getMatch(){
System.out.println("With transaction " + getSession().hashCode() );
}
The hashcodes are not the same. Should they be?
I would like to be able to lookup the entitymanager/session, so that I dont have to pass i around as a parameter.
Best,
Anders