Reputation: 7380
I'm trying to migrate a Spring application from JBoss AS 4.0.5.GA to 7.1.1.Final. In my jboss-spring.xml
there is one bean, engine
, whose init method results in the createQuery
row below being executed.
public class QueueConfigurationDAO {
private EntityManager _entityManager;
@PersistenceContext
public void setEntityManager(EntityManager entityManager) {
_entityManager = entityManager;
}
public List<QueueConfiguration> getQueueConfigurations() {
Query query = _entityManager.createQuery("from QueueConfiguration");
return query.getResultList();
}
}
This results in the following stacktrace:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'engine' defined in "/C:/Users/Emil/JBoss/jboss-as-7.1.1.Final/standal
one/deployments/zz10-wf.spring/META-INF/jboss-spring.xml": Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: org.hibernate.hql.i
nternal.ast.QuerySyntaxException: QueueConfiguration is not mapped [from QueueConfiguration]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1488)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:524)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.jboss.spring.factory.NamedXmlApplicationContext.<init>(NamedXmlApplicationContext.java:69)
at org.jboss.spring.factory.NamedXmlApplicationContext.<init>(NamedXmlApplicationContext.java:59)
at org.jboss.spring.deployers.as7.SpringBootstrapProcessor.deploy(SpringBootstrapProcessor.java:69)
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:113) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
... 5 more
Caused by: java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: QueueConfiguration is not mapped [from QueueConfiguration]
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1348)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1289)
at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:288)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_02]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_02]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_02]
at java.lang.reflect.Method.invoke(Method.java:601) [rt.jar:1.7.0_02]
at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:241)
at $Proxy118.createQuery(Unknown Source) at se.sunstone.workflow.queues.QueueConfigurationDAO.getQueueConfigurations(QueueConfigurationDAO.java:28)
at se.sunstone.workflow.queues.StandardQueueManager.configure(StandardQueueManager.java:71)
at se.sunstone.workflow.queues.StandardQueueManager.start(StandardQueueManager.java:52)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_02]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_02]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_02]
at java.lang.reflect.Method.invoke(Method.java:601) [rt.jar:1.7.0_02]
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy121.start(Unknown Source) at se.sunstone.workflow.engine.ExecutionEngine.start(ExecutionEngine.java:177)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_02]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_02]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_02]
at java.lang.reflect.Method.invoke(Method.java:601) [rt.jar:1.7.0_02]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1614)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1555)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1485)
... 18 more
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: QueueConfiguration is not mapped [from QueueConfiguration]
at org.hibernate.hql.internal.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:180)
at org.hibernate.hql.internal.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:110)
at org.hibernate.hql.internal.ast.tree.FromClause.addFromElement(FromClause.java:93)
at org.hibernate.hql.internal.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:326)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3252)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:3141)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:694)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:550)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:287)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:235)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:248)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:183)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:101)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:119)
at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:214)
at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:192)
at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1537)
at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:285)
... 48 more
I suppose that QuerySyntaxException: QueueConfiguration is not mapped
means that my
@javax.persistence.Entity
@javax.persistence.Table(name = "queue_configuration")
public class QueueConfiguration { /* ... */ }
class is not recognized as an entity by Hibernate. Indeed, when I run the application in JBoss 4, the startup logs contain rows like
INFO [org.hibernate.cfg.AnnotationBinder] Binding entity from annotated class: se.sunstone.workflow.queues.QueueConfiguration
but no such rows appear in the log when I try to deploy it in JBoss 7. If I comment out the engine
bean from jboss-spring.xml
, the application happily deploys without exceptions.
I'm using JBoss 7's built-in Hibernate module and I'm deploying my webapp using the Snowdrop module. I have monkeyed around with this for a few days now, including trying to use Hibernate 3 instead, but the problem persists.
If I explicitly specify <class>se.sunstone.workflow.queues.QueueConfiguration</class>
in persistence.xml
, the application deploys and the logs now contain the same AnnotationBinder rows as when running on JBoss 4. However, the application also has a bunch of other annotated entities, whose DAOs are omitted from the configs below, and they are not detected unless I specify them too in persistence.xml
. Apparently the AnnotationBinder does not detect my annotated entities unless I specify them in persistence.xml
. Why is that?
Archive layout:
zz10-wf.spring
-- META-INF
---- jboss-deployment-structure.xml
---- jboss-spring.xml
---- jpa-persistence.xml
---- MANIFEST-MF
-- (Java package hierarchy)
Following these instructions I have renamed the traditional persistence.xml
to jpa-persistence.xml
so that JBoss will not detect it and launch its own Hibernate instance.
zz10-wf.spring
is currently deployed as an exploded directory, but the same thing happens if I deploy it as an uncompressed zip archive.
jboss-deployment-structure.xml
:
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0">
<deployment>
<exclusions>
<module name="org.hibernate"/>
</exclusions>
</deployment>
</jboss-deployment-structure>
jboss-spring.xml
:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-2.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<!-- ========= Central application configuration ========= -->
<bean id="queueManager" class="se.sunstone.workflow.queues.StandardQueueManager">
<property name="queueConfigurationDAO" ref="queueConfigurationDAO"/>
</bean>
<bean id="engine" class="se.sunstone.workflow.engine.ExecutionEngine" init-method="start" destroy-method="stop">
<property name="queueManager" ref="queueManager"/>
</bean>
<!-- ========= DAOs ========= -->
<bean id="queueConfigurationDAO" class="se.sunstone.workflow.queues.QueueConfigurationDAO" />
<!-- ========= JPA ========= -->
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceXmlLocation" value="classpath*:META-INF/jpa-persistence.xml"/>
<property name="dataSource" ref="dataSource"/>
<property name="persistenceUnitName" value="workflow" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="false" />
<property name="generateDdl" value="true" />
<property name="databasePlatform" value="org.hibernate.dialect.PostgreSQLDialect"/>
</bean>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<tx:annotation-driven />
<jee:jndi-lookup id="dataSource" jndi-name="java:jboss/WorkflowDS"/>
</beans>
jpa-persistence.xml
:
<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="workflow">
<!-- <class>se.sunstone.workflow.queues.QueueConfiguration</class> -->
</persistence-unit>
</persistence>
I have tried moving configuration details back and forth between jpa-persistence.xml
and the entityManagerFactory
bean definition, the results are largely the same and the application agrees to run with this minimal jpa-persistence.xml
as long as the QueueConfiguration
row above is uncommented.
Upvotes: 2
Views: 1466
Reputation: 839
Kindly update "entityManagerFactory" bean in jboss-spring.xml as follows:
Sample (replace "your_jpa_related_base_package" with actual one):
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<!--
<property name="persistenceXmlLocation" value="classpath*:META-INF/jpa-persistence.xml"/>
-->
<property name="dataSource" ref="dataSource"/>
<property name="packagesToScan" value="your_jpa_related_base_package" />
<property name="persistenceUnitName" value="workflow" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="false" />
<property name="generateDdl" value="true" />
<property name="databasePlatform" value="org.hibernate.dialect.PostgreSQLDialect"/>
</bean>
</property>
Upvotes: 0
Reputation: 7380
In an earlier incarnation of this question, one of my questions was why AnnotationBinder ran twice. I think this was because JBoss detected persistence.xml
and launched its own Hibernate instance in parallel to the one launched by Spring. After renaming persistence.xml
to jpa-persistence.xml
(any other name would probably do, though) as described in the JBoss AS 7 documentation, this behaviour stopped. The problem with AnnotationBinder not detecting annotated entities persists, however.
I edited these questions out of the Question since I want the Question to be more specifically about why the AnnotationBinder does not detect annotated entities.
Upvotes: 1