-
1. We are getting the Hibernate Exception
wdfink Mar 24, 2011 3:14 AM (in response to vacajboss)Sound that you use direct the implementation for the EntityManager instead of interfaces and the implementation changed.
Could you provide more information and a pice of code?
-
2. We are getting the Hibernate Exception
vandu620 Mar 24, 2011 1:16 PM (in response to wdfink)This exception happens when we are using findEntityById() method which has the following code
org.hibernate.ejb.HibernateEntityManager hbEm= ((org.hibernate.ejb.HibernateEntityManager)em);
We are casting the entity manager to the HibernateEntityManager.
Is there any workaround for this casting problem exception?
-
3. We are getting the Hibernate Exception
wdfink Mar 24, 2011 1:57 PM (in response to vandu620)Why do you cast the EM to a special implementation?
Where the 'em' is from.
Post a bit more of the relevant code that it is understandable what you try to do.
-
4. Re: We are getting the Hibernate Exception
vandu620 Mar 24, 2011 4:25 PM (in response to wdfink)I am really not sure about the special implementation
The em is from javax.persistence.EntityManager and we are casting to the specific Hibernate Entity Manager and below is the code in our methods...
This casting was working perfectly fine on Jboss 4.3.4GA but failing on Jboss5.0.1
public T findEntityById(T exampleInstance, long entityId) throws EJBServiceException {
T entityT;
org.hibernate.ejb.HibernateEntityManager hbmEm = ((org.hibernate.ejb.HibernateEntityManager)em);
entityT = (T)hbmEm.find(exampleInstance.getClass(), entityId);
return entityT;
}
@SuppressWarnings("unchecked")
public List findByCriteria(Criterion... criterions) throws EJBServiceException {
org.hibernate.Criteria crit = ((org.hibernate.ejb.HibernateEntityManager)em) .getSession() .createCriteria(getEntityBeanType());
for (Criterion criterion : criterions) {
crit.add(criterion);
}
return crit.list();
}
-
5. Re: We are getting the Hibernate Exception
jaikiran Mar 25, 2011 3:49 AM (in response to vandu620)Why are you casting it to org.hibernate.ejb.HibernateEntityManager? Just cast it to javax.persistence.EntityManager
-
6. Re: We are getting the Hibernate Exception
angelocavalier Sep 19, 2011 10:27 AM (in response to vandu620)Hi VM,
JBoss 5.0.1 use TransactionScopedEntityManager, cast yous EntityManager to TransactionScopedEntityManager and use method "getHibernateSession" to use hibernate functionalities.
Some like this:
public List findByCriteria(Criterion... criterions) throws EJBServiceException {
org.hibernate.Criteria crit = ( (org.jboss.jpa.tx.TransactionScopedEntityManager) em) .getHibernateSession() .createCriteria(getEntityBeanType());
for (Criterion criterion : criterions) {
crit.add(criterion);
}
return crit.list();
}