我遇到了一个奇怪的问题,我的实体经理没有提交到数据库。我已经检查了我的日志,没有发现任何错误,查询似乎执行得很好。来自JPATransactionManager的调试语句表明它正在调用该方法并尝试合并/持久但是我没有显示hibernate insert语句日志中。
使用Jboss 6.1.0和Spring 3.1.1
的web.xml:
` <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
metadata-complete="true">
<display-name>spring-intel</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:META-INF/spring/applicationContext*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>IntelWsClient</servlet-name>
<servlet-class>com.ijet.service.intel.IntelWsDriver</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>IntelWsClient</servlet-name>
<url-pattern>/IntelWsClient</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
的applicationContext.xml:
<context:component-scan base-package="com.pwo.dao" />
<context:annotation-config/>
<tx:annotation-driven transaction-manager="txManager"/>
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
<property name="persistenceUnitName" value="myPU" />
</bean>
<bean id="txManager" class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="transactionManagerName" value="java:TransactionManager"/>
<property name="userTransactionName" value="UserTransaction"/>
</bean>
</beans>
存储库类:
@Service("myService")
public class MyServiceImpl implements MyService {
@PersistenceContext
EntityManager em;
public void setEntityManager(EntityManager em) {
this.em = em;
}
@Transactional(propagation = Propagation.SUPPORTS)
public Item findItem(Integer itemId) {
return em.find(Item.class, itemId);
}
@Transactional(propagation = Propagation.REQUIRED)
public void storeItem(Item item) {
if (item != null && item.getId() != null) {
em.merge(item);
} else
em.persist(item);
em.flush();
}
}
的persistence.xml
<persistence-unit name="myPU" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:pwo-DS</jta-data-source>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="hibernate.validator.autoregister_listeners" value="false"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.OracleDialect"/>
<!--property name="hibernate.cache.use_query_cache" value="false"/-->
<property name='hibernate.cache.provider_class' value='org.hibernate.cache.EhCacheProvider'/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.order_inserts" value="true"/>
<property name="hibernate.order_updates" value="true"/>
<property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
</properties>