Hibernate problem - Unknown entity when doing find or persist

Solution Verified - Updated -

Issue

  • Problem occurred when calling find or persist method.
  • User is using EAP 5.2 for this issue.
  • User is getting the below exception in server.log file :
2015-01-28 13:35:14,399 ERROR [org.jboss.aspects.tx.TxPolicy] (WorkManager(2)-6) javax.ejb.EJBTransactionRolledbackException: Unknown entity: 
a.b.database.entities.EntityTest
at org.jboss.ejb3.tx.Ejb3TxPolicy.handleInCallerTx(Ejb3TxPolicy.java:115)
    at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:130)
.......
java.lang.IllegalArgumentException: Unknown entity: a.b.database.entities.EntityTest
        at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:193)
        .....
org.hibernate.MappingException: Unknown entity: a.b.database.entities.EntityTest
        at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:629)
        at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:91)
        .....

Please suggest why is this happening?

  1. User is using javax.persistence.Entity.
  2. The entity is used at runtime before the exception occurs and it suddenly happen.
  3. User has 2 EARs that has the same Entity. Each EAR has the same database.jar which contains this Entity and maybe that is the cause.
  4. User configured the property <property name="isolated">true</property> in this file: server\default\deployers\ear-deployer-jboss-beans.xml
  5. Since user use JPA do not use hibernate.cfg.xml at all but using persistence.xml
  6. Here is in the log file this stack trace that shows that the entity was loaded:
2015-01-28 13:35:13,135 TRACE [org.hibernate.event.def.DefaultLoadEventListener] (Thread-2361) loading entity: [a.b.database.entities.EntityTest#234567]
2015-01-28 13:35:13,135 TRACE [org.hibernate.event.def.DefaultLoadEventListener] (Thread-2361) attempting to resolve: [a.b.database.entities.EntityTest#234567]
2015-01-28 13:35:13,135 TRACE [org.hibernate.event.def.DefaultLoadEventListener] (Thread-2361) object not resolved in any cache: [a.b.database.entities.EntityTest#234567]
2015-01-28 13:35:13,135 TRACE [org.hibernate.persister.entity.AbstractEntityPersister] (Thread-2361) Fetching entity: [ca.b.database.entities.EntityTest#234567]
2015-01-28 13:35:13,135 DEBUG [org.hibernate.loader.Loader] (Thread-2361) loading entity: [a.b.database.entities.EntityTest#234567]
2015-01-28 13:35:13,135 DEBUG [org.hibernate.jdbc.AbstractBatcher] (Thread-2361) about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
2015-01-28 13:35:13,135 DEBUG [org.hibernate.jdbc.ConnectionManager] (Thread-2361) opening JDBC connection
2015-01-28 13:35:13,135 DEBUG [org.hibernate.SQL] (Thread-2361) 
    select
        abc0_.ac_no as ac1_14_0_,
        abc0_.b_id as b2_14_0_,
        abc0_.w as w3_14_0_,
        abc0_.f as f4_14_0_ 
    from
        entity_test abc0_ 
    where
        abc0_.ac_no=?
2015-01-28 13:35:13,135 TRACE [org.hibernate.jdbc.AbstractBatcher] (Thread-2361) preparing statement
2015-01-28 13:35:13,151 DEBUG [org.hibernate.jdbc.AbstractBatcher] (Thread-2361) about to open ResultSet (open ResultSets: 0, globally: 0)
2015-01-28 13:35:13,151 TRACE [org.hibernate.loader.Loader] (Thread-2361) processing result set
2015-01-28 13:35:13,151 DEBUG [org.hibernate.loader.Loader] (Thread-2361) result set row: 0
2015-01-28 13:35:13,151 DEBUG [org.hibernate.loader.Loader] (Thread-2361) result row: EntityKey[a.b.database.entities.EntityTest#234567]
2015-01-28 13:35:13,151 TRACE [org.hibernate.loader.Loader] (Thread-2361) Initializing object from ResultSet: [a.b.database.entities.EntityTest#234567]
2015-01-28 13:35:13,151 TRACE [org.hibernate.persister.entity.AbstractEntityPersister] (Thread-2361) Hydrating entity: [a.b.database.entities.EntityTest#234567]
2015-01-28 13:35:13,151 TRACE [org.hibernate.loader.Loader] (Thread-2361) done processing result set (1 rows)
2015-01-28 13:35:13,151 DEBUG [org.hibernate.jdbc.AbstractBatcher] (Thread-2361) about to close ResultSet (open ResultSets: 1, globally: 1)
2015-01-28 13:35:13,151 DEBUG [org.hibernate.jdbc.AbstractBatcher] (Thread-2361) about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2015-01-28 13:35:13,151 TRACE [org.hibernate.jdbc.AbstractBatcher] (Thread-2361) closing statement
  • While migrating Issue from AS 7.1.1-Final to EAP 6.3 we are getting
java.lang.IllegalArgumentException: Unknown entity: xx.xx.xx.xx
  • We are in process of migrating from AS 7.1.1-final to EAP 6.3.
  • We are facing issue related to entity not found code is running without any issue in AS edition but giving error in EAP , This error rate is high need your help to fix this.
16:59:39,173 ERROR [stderr] (http-127.0.0.1/127.0.0.1:8443-7) java.lang.IllegalArgumentException: Unknown entity: xx.xx.xx.xx

16:59:39,174 ERROR [stderr] (http-127.0.0.1/127.0.0.1:8443-7)   at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:829)

16:59:39,174 ERROR [stderr] (http-127.0.0.1/127.0.0.1:8443-7)   at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:781)

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP)
    • 6.x
    • 5.x

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.

Current Customers and Partners

Log in for full access

Log In
Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.