Warum werden JPA-Änderungen mit einem EntityManager durchgeführt, der nicht in einem Spring Service festgeschrieben ist, wenn JtaTransactionManager verwendet wird?

Ich muss @ verwendorg.springframework.transaction.jta.JtaTransactionManager wie meinTransactionManager im FrühlingService. Es werden jedoch keine Änderungen an JPA-Entitäten festgeschrieben. Ich weiß das, wenn ich @ benutJpaTransactionManager Es klappt. Aber ich braucheJtaTransactionManager. Also, bitte nicht empfehlen, @ zu verwendJpaTransactionManager. Mein FrühlingService Klasse ist:

package testspring.view;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import testspring.model.Regions;


@Service
public class HelloBS {
    @PersistenceContext
    private EntityManager entityManager;

    public HelloBS() {
        super();
    }

    @Transactional()
    public void doSomething() {
        Regions region = new Regions();
        region.setRegionName("Antarctica");
        entityManager.persist(region);
    }
}

Und meine Spring xml Konfiguration ist:

<?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 class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <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"
          class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName" value="jdbc/hrDS"/>
        <property name="resourceRef" value="true"/>
    </bean>
    <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
    <bean id="entityManagerFactory"
          class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="packagesToScan" value="testspring.model"/>
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>
        </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.useUnicode">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>
            </props>
        </property>
    </bean>
    <bean id="transactionManager"
          class="org.springframework.transaction.jta.JtaTransactionManager"></bean>
    <tx:annotation-driven transaction-manager="transactionManager"/>
</beans>

Wie kann ich Änderungen an JPA-Entitäten vornehmen lassen, die mit @ festgeschrieben wurdeJtaTransactionManager?

Antworten auf die Frage(2)

Ihre Antwort auf die Frage