I know that my post is a liitle to long, but please read carefully. I know that I can create global JNDI of my persistence unit by some properties in persistence.xml! Lookup on this jndi will return EntityManager or EntityManagerFactory(depends on property). I am using Hibernate and I must get SessionFactory (Hibernate). This cool integration :http://bill.burkecentral.com/2007/07/06/co-existence-with-hibernate-jpa-and-ejb3 can mix hibernate with jpa and ejb3 from JBOSS. This is very cool feature becouse Jboss create for U SessionFactory object and U can inject this object with nice annotation (@PersistenceUnit). Later I was trying Hibernate MBean in JBoss but this solution is not universal and it's slowly departs (for example there is a couple important properties that is not mapped to Jboss MBean Hibernate service). My question was about naming convention in Jboss. Server automatically bind SessionFactory described in persistence.xml but the name of jndi is unacceptable. Can i change name of this jndi ?
Riddick Pu wrote:
I know that I can use properties like: <property name="jboss.entity.manager.jndi.name" value="java:/Manager1"/> ... in persistence.xml file to create global JNDI of my persistence unit. This solution is not satisfactory becouse the InitialContext.lookup returns EntityManager object while I want SessionFactory
You can do this:
EntityManager em = (EntityManager) initialCtx.lookup("java:/Manager1"); SessionFactory sessionFactory = em.unwrap(Session.class).getSessionFactory();
where Session and SessionFactory are from the appropriate Hibernate package.