Advertise with us

Our eBooks

How to access Hibernate objects from EJB 3.0 ?

JBoss recipe of the day

Basically you need to cast objects to Hibernate types. For example:

Getting Hibernate Session

You can get access to the current underlying Hibernate Session by typecasting your reference to EntityManager.:

       @PersistenceContext EntityManager entityManager;
       public void someMethod();
       {
         org.jboss.ejb3.entity.HibernateSession hs = (HibernateSession)entityManager;
         org.hibernate.Session session = hs.getHibernateSession();
       }

Getting Hibernate Query

You can get access to the current underlying Hibernate Query by typecasting your reference to a org.hibernate.ejb.QueryImpl.

       @PersistenceContext EntityManager entityManager;
       public void someMethod();
       {
         javax.persistence.Query query = entityManager.createQuery(...);
         org.hiberante.ejb.QueryImpl hs = (QueryImpl)query;
         org.hibernate.Query hbQuery = hs.getHibernateQuery();
       }
© 2021 mastertheboss.com. All Rights Reserved.

Please publish modules in offcanvas position.