JBOSS 6.1 final: Entity Beans not mapped
amitsoprna Jul 31, 2012 7:06 AMWe 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.