栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

使用JtaTransactionManager时,为什么未在Spring Service中提交使用EntityManager的JPA更改?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用JtaTransactionManager时,为什么未在Spring Service中提交使用EntityManager的JPA更改?

感谢 @Bond-Java Bond ,解决方案是执行以下步骤:

  • 设置
    jtaDataSource
    dataSource
  • 使用
    <tx:jta-transaction-manager/>
    代替
    <tx:annotation-driven transaction-manager="transactionManager"/>
  • 添加
    <prop key="hibernate.transaction.jta.platform">org.hibernate.service.jta.platform.internal.WeblogicJtaPlatform</prop>
    org.hibernate.service.jta.platform.internal
    软件包中有不同的类,可用于不同的Application Server。

因此,最终的Spring xml配置为:

<?xml version="1.0" encoding="UTF-8" standalone="no"?><beans xmlns="http://www.springframework.org/schema/beans"       xmlns:context="http://www.springframework.org/schema/context"       xmlns:tx="http://www.springframework.org/schema/tx"       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"       xmlns:mvc="http://www.springframework.org/schema/mvc"       xmlns:jee="http://www.springframework.org/schema/jee"       xsi:schemaLocation="    http://www.springframework.org/schema/beans    http://www.springframework.org/schema/beans/spring-beans-3.2.xsd    http://www.springframework.org/schema/tx    http://www.springframework.org/schema/tx/spring-tx-3.2.xsd    http://www.springframework.org/schema/context    http://www.springframework.org/schema/context/spring-context-3.2.xsd    http://www.springframework.org/schema/mvc    http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd    http://www.springframework.org/schema/jee     http://www.springframework.org/schema/jee/spring-jee-3.2.xsd">    <context:component-scan base-package="testspring.view"/>    <context:annotation-config/>    <mvc:annotation-driven/>    <bean >        <property name="viewClass"       value="org.springframework.web.servlet.view.JstlView"/>        <property name="prefix" value="/WEB-INF/jsp/"/>        <property name="suffix" value=".jsp"/>    </bean>    <mvc:default-servlet-handler/>    <bean id="dataSource" name="dataSource"          >        <property name="jndiName" value="jdbc/hrDS"/>        <property name="resourceRef" value="true"/>    </bean>    <bean />    <bean id="entityManagerFactory"          >        <property name="jtaDataSource" ref="dataSource"/>        <property name="packagesToScan" value="testspring.model"/>        <property name="jpaVendorAdapter"> <bean />        </property>     <property name="jpaProperties"> <props>     <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>     <prop key="javax.persistence.validation.mode">AUTO</prop>     <prop key="hibernate.archive.autodetection">class</prop>     <prop key="hibernate.ejb.naming_strategy">org.hibernate.cfg.ImprovedNamingStrategy</prop>     <prop key="hibernate.connection.charSet">UTF-8</prop>     <prop key="hibernate.connection.useUnipre">true</prop>     <prop key="hibernate.connection.characterEncoding">UTF-8</prop>     <prop key="hibernate.show_sql">true</prop>     <prop key="hibernate.format_sql">true</prop>     <prop key="hibernate.transaction.flush_before_completion">true</prop>     <prop key="hibernate.transaction.auto_close_session">true</prop>     <prop key="hibernate.connection.release_mode">auto</prop>     <prop key="hibernate.transaction.jta.platform">org.hibernate.service.jta.platform.internal.WeblogicJtaPlatform</prop> </props>        </property>    </bean>    <tx:jta-transaction-manager/></beans>


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/403569.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号