JPA spring @Transaction autocommit

时间:2014-03-12 11:19:41

标签: java transactions spring-data-jpa

我正在使用带有oracle的spring-data-jpa。对于运行时异常,我无法让@Transactional默认回滚。

以下是片段:

<persistence-unit name="dev2db" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <properties>
            <property name="hibernate.archive.autodetection" value="class, hbm"/>
            <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
            <property name="hibernate.hbm2ddl.auto" value="validate" />

            <property name="javax.persistence.jdbc.driver" value="oracle.jdbc.OracleDriver" />
            <property name="javax.persistence.jdbc.url" value="jdbc:oracle:thin:@host:port" />
            <property name="javax.persistence.jdbc.user" value="loginid" />
            <property name="javax.persistence.jdbc.password" value="mypass" />
        </properties>
    </persistence-unit>

事务方法使用import javax.transaction.Transactional;

@Transactional
    public void uploadPanelAndAPK(String pz, byte[] file, String apk, byte[] fileApk, byte[] icon) {
        uploadPanel(pz, file);
        uploadApk(apk, fileApk, icon);

    }

如果uploadApk失败,则uploadPanel不会进行回滚。

beans context.xml片段:

<context:annotation-config />
    <tx:annotation-driven transaction-manager="transactionManager"/>
    <jpa:repositories base-package="com.myco.dao" />

    <bean id="transactionManager" 
          class="org.springframework.orm.jpa.JpaTransactionManager"
          p:entityManagerFactory-ref="entityManagerFactory"/>


    <bean id="entityManagerFactory" 
          class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
          p:persistenceUnitName="dev2db">
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
        </property>
    </bean>

    <bean id="panelbo" class="com.myco.bo.PanelServiceSpringData"/> 

此致

米滕。

1 个答案:

答案 0 :(得分:2)

javax.transaction.Transactional尚未得到支持。使用javax.ejb.TransactionAttributeorg.springframewor.transaction.annotation.Transactional