6 Replies Latest reply on Jul 31, 2012 7:37 AM by periklis_douvitsas

    JBOSS 6.1 final: Entity Beans not mapped

    amitsoprna

      We have migrated from JBOSS4.2 to JBOSS6.1 final.

      Following is our ear structure

       

      my_application1.ear

                  |-------------my_application_common_beans.jar

                                          |--------META-INF/persistence.xml

                  |-------------my_application1.war

       

      my_application2.ear

                  |-------------my_application_common_beans.jar

                                          |--------META-INF/persistence.xml

                  |-------------my_application2.war

       

      These two ears are deployed within the same server instance. "my_application_common_beans.jar" is the jar containing all the entity beans and it has the persistence.xml inside it too in the META_INF folder.

       

      This configuration used to work in JBOSS4.2 but it is not working in JBOSS6.1. Although the server logs shows that entities are scanned and bind at the server startup. Following are some lines from the log file:

       

      01:13:51,832 INFO  [PersistenceUnitDeployment] Starting persistence unit persistence.unit:unitName=my_application1.ear/my_application_common_beans.jar#myapplication-core

      01:13:51,833 INFO  [Ejb3Configuration] Processing PersistenceUnitInfo [

          name: myapplication-core

          ...]

      01:13:51,894 WARN  [Ejb3Configuration] Persistence provider caller does not implement the EJB3 spec correctly.PersistenceUnitInfo.getNewTempClassLoader() is null.

      01:13:51,894 WARN  [Ejb3Configuration] Overriding hibernate.transaction.factory_class is dangerous, this might break the EJB3 specification implementation

      01:13:51,894 WARN  [Ejb3Configuration] Defining hibernate.transaction.flush_before_completion=true ignored in HEM

      01:13:51,940 INFO  [AnnotationBinder] Binding entity from annotated class: myapplication.package1.ejb.User

      01:13:51,941 INFO  [EntityBinder] Bind entity myapplication.package1.ejb.User on table user

      01:13:51,952 INFO  [AnnotationBinder] Binding entity from annotated class: myapplication.package1.ejb.Employee

      01:13:51,953 INFO  [EntityBinder] Bind entity myapplication.package1.ejb.Employee on table employee

      .....

      ....

      and so on, so it seems it scans the beans directory and binds them with the persistence unit.

       

      But when the application tries to do a query on any of these objects it throws the following exception:

       

      Caused by: java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: User is not mapped [FROM User usr WHERE usr.name=:n]

          at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1202) [:3.6.6.Final]

          at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1148) [:3.6.6.Final]

          at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:275) [:3.6.6.Final]

          at myapplication.package2.builder.UserBuilderImpl.getUserByName(UserBuilderImpl.java:55) [:]

          ... 92 more

      Caused by: org.hibernate.hql.ast.QuerySyntaxException: User is not mapped [FROM User usr WHERE usr.name=:n]

          at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:180) [:3.6.6.Final]

          at org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:111) [:3.6.6.Final]

          at org.hibernate.hql.ast.tree.FromClause.addFromElement(FromClause.java:93) [:3.6.6.Final]

          at org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:327) [:3.6.6.Final]

          at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3441) [:3.6.6.Final]

          at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:3325) [:3.6.6.Final]

          at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:733) [:3.6.6.Final]

          at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:584) [:3.6.6.Final]

          at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:301) [:3.6.6.Final]

          at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:244) [:3.6.6.Final]

          at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:254) [:3.6.6.Final]

          at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:185) [:3.6.6.Final]

          at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136) [:3.6.6.Final]

          at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101) [:3.6.6.Final]

          at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80) [:3.6.6.Final]

          at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:124) [:3.6.6.Final]

          at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156) [:3.6.6.Final]

          at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135) [:3.6.6.Final]

          at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1770) [:3.6.6.Final]

          at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:272) [:3.6.6.Final]

          ... 93 more

       

      Following is my persistence.xml

       

      <?xml version="1.0" encoding="UTF-8"?>

      <persistence

          xmlns="http://java.sun.com/xml/ns/persistence"

          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

          xsi:schemaLocation="http://java.sun.com/xml/ns/persistence

          http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"

          version="1.0">

          <persistence-unit name="myapplication-core" transaction-type="RESOURCE_LOCAL">

              <provider>org.hibernate.ejb.HibernatePersistence</provider>

              <non-jta-data-source>java:/MyApplicationDS</non-jta-data-source>

              <properties>

                  <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />

                  <property name="hibernate.cache.use_query_cache" value="false" />

                  <property name="hibernate.show_sql" value="false" />

                  <property name="jboss.entity.manager.jndi.name" value="java:/EntityManagers/myapplication-core" />

                  <property name="jboss.entity.manager.factory.jndi.name" value="java:/EntityManagers/myapplication-core-factory" />

                  <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />

                  <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup" />

                  <property name="hibernate.transaction.factory_class" value="org.hibernate.transaction.JTATransactionFactory" />

                  <property name="hibernate.transaction.flush_before_completion" value="true" />

                  <property name="hibernate.connection.release_mode" value="auto" />

              </properties>

          </persistence-unit>

      </persistence>

       

      Can anyone please help me out on this. Is there anything that I need to set for this to work in JBOSS6.1.

      What could be the problem, I have already googled and browsed the forum but did not find anything matching to my problem. There are some threads though where people cited similar problem but i guess there solution were specific to Spring and I am not using Spring. Also there were some suggestions of writing a customized entity scanner but that doesn't seems to be proper solution to me or is that the only solution?

       

      Thanks a lot in advance.

        • 1. Re: JBOSS 6.1 final: Entity Beans not mapped
          periklis_douvitsas

          Hi, have a look at this post

          https://community.jboss.org/thread/168447

           

          In your EJB do you use the old import javax.annotation.EJB

          or do you use javax.ejb.EJB?

           

          Hope this helps

          • 2. Re: JBOSS 6.1 final: Entity Beans not mapped
            amitsoprna

            This problem gets resolved if I mention all the entity beans in the persistence.xml as

             



            <class>myapplication.package1.ejb.User</class>

             

            But problem is we generate Entity Beans with middlegen tool. So everytime a new table gets added we got to go and modify the persistence.xml that is what I do not want. What has changed in JBOSS6.1 that now necessitate mentioning the entity bean classes in the persistence.xml?

            • 3. Re: JBOSS 6.1 final: Entity Beans not mapped
              amitsoprna

              Hi Periklis thanks for the quick response. The annotation on my classes are like:

               

              @javax.persistence.Entity

              @javax.persistence.Table(name = "user")

              • 4. Re: JBOSS 6.1 final: Entity Beans not mapped
                periklis_douvitsas

                Sorry,

                I read your question very fast and my proposal i am not sure it was correct for your problem. The suggestion i said involved the beans and not the entities. The annotations you use for the entities look ok.have a look at this also, 

                https://community.jboss.org/thread/111035?start=15&tstart=0

                 

                Also, can you give an example (code) how do you call an entity bean?

                • 5. Re: JBOSS 6.1 final: Entity Beans not mapped
                  amitsoprna

                  Yea the problem explained on that thread seems to be similar to my problem but no solutions or directions are provided over there. Following is the example code that we use:

                   

                  import javax.persistence.EntityManager;

                  import javax.persistence.EntityManagerFactory;

                  import javax.persistence.Persistence;

                  import javax.persistence.NoResultException;

                  import javax.persistence.Query;

                   

                   

                      public User getUserByName(String userName) throws BAException {
                          EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("myapplication-core");
                          EntityManager manager = entityManagerFactory.createEntityManager();
                          User user= null;       
                          try {
                              Query q = manager.createQuery("FROM User usr WHERE usr.name=:n");
                              q.setParameter("n", userName);               
                              logger.debug("Executing query with user name = " + userName);
                              user = (User) q.getSingleResult();
                          }
                          catch (NoResultException nrex) {
                              logger.debug("Found no matching results for user name = " + userName);
                          }
                          catch (Exception e) {
                              logger.debug(e);
                              throw new MyApplicationException("Error while trying to get a User based on the name = " + userName, e);
                          }
                          return user;
                      }

                  • 6. Re: JBOSS 6.1 final: Entity Beans not mapped
                    periklis_douvitsas

                    I am not sure what your problem is

                     

                    For the above code you can also use the code below to get the EntityManager

                     

                    @PersistenceContext(name = "myapplication-core")

                    EntityManager manager;

                     

                    Also, the other thing you can do is to try to remove all your properties in the persistence.xml (except the <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />) and anything else you find necessary.

                     

                    maybe the warnings are not so innocent.

                    01:13:51,894 WARN  [Ejb3Configuration] Persistence provider caller does not implement the EJB3 spec correctly.PersistenceUnitInfo.getNewTempClassLoader() is null.

                    01:13:51,894 WARN  [Ejb3Configuration] Overriding hibernate.transaction.factory_class is dangerous, this might break the EJB3 specification implementation

                    01:13:51,894 WARN  [Ejb3Configuration] Defining hibernate.transaction.flush_before_completion=true ignored in HEM