我正在使用带有hibernate JTA,因此我有一个包含多个war文件的Ear文件,当我在glassfish中部署Ear文件时,它运行得很好,但当我在Jboss中运行Ear文件时,它会给我一些错误
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [persistenceContext.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: EW] Unable to build EntityManagerFactory
16:54:55,678 ERROR [stderr] (MSC service thread 1-8) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1486)
16:54:55,678 ERROR [stderr] (MSC service thread 1-8) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:524)
16:54:55,679 ERROR [stderr] (MSC service thread 1-8) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
16:54:55,680 ERROR [stderr] (MSC service thread 1-8) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
16:54:55,680 ERROR [stderr] (MSC service thread 1-8) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
16:54:55,681 ERROR [stderr] (MSC service thread 1-8) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
16:54:55,682 ERROR [stderr] (MSC service thread 1-8) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
16:54:55,682 ERROR [stderr] (MSC service thread 1-8) at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1117)
16:54:55,683 ERROR [stderr] (MSC service thread 1-8) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:922)
16:54:55,683 ERROR [stderr] (MSC service thread 1-8) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
16:54:55,684 ERROR [stderr] (MSC service thread 1-8) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
16:54:55,685 ERROR [stderr] (MSC service thread 1-8) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
16:54:55,685 ERROR [stderr] (MSC service thread 1-8) at com.eyewatch.dao.util.DAOLocator.<clinit>(DAOLocator.java:15)
发布于 2014-03-27 19:49:37
要使用JBOSS JTA,除了<jta-data-source>
之外,不应该在persistence.xml
中配置任何内容
要在Spring应用程序中使用JBOSS JTA,只需将以下代码添加到config:
<tx:jta-transaction-manager/>
注意,最好允许将持久性单元提升到JBOSS:将persistence.xml
放到jar的META-INF
中。并从JNDI获取entityManagerFactory
:
persistence.xml
<property name="jboss.entity.manager.factory.jndi.name" value="persistence/MY-UNIT"/>
application.xml
<jee:jndi-lookup id="emf" jndi-name="persistence/MY-UNIT"/>
<bean id="entityManager" class="org.springframework.orm.jpa.support.SharedEntityManagerBean"
p:entityManagerFactory-ref="emf"/>
这样,您就可以继续在服务中使用@PersistenceContext
https://stackoverflow.com/questions/22686385
复制相似问题