使用JTA与Spring + hibernate JPA + Glassfish 3.1交易不提交

时间:2012-03-06 13:22:26

标签: spring hibernate jpa glassfish jta

我一直在努力解决这个问题,但我搜索了整个互联网,但无济于事。我希望你的家伙可以帮助我 我使用带有hibernate JPA和spring 3的glassfish 3.1。 我在Glassfish中配置了一个数据源和池来定位MYSQL 请找到我的配置

Web.xml,我配置了持久性单元。

  <persistence-unit-ref>
    <description>Persistence Unit for PlyPlus</description>
    <persistence-unit-ref-name>
    persistence/zeneJPA
    </persistence-unit-ref-name>
    <persistence-unit-name>
    ZeneJPA
    </persistence-unit-name>
    </persistence-unit-ref>

应用程序上下文

  <context:component-scan base-package="com.binarydna.store" />
    <bean        class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor">
     <property name="persistenceUnits">
     <map>
     <entry key="ZeneJPA" value="persistence/zeneJPA">
     </entry>
     </map>
     </property>
     </bean>
        <!-- 
     <bean id="entityManagerFactory"   class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
     <property name="persistenceUnitName" value="ZeneJPA"/>
     </bean>
     -->
     <!-- We want to use Spring's declarative @Transaction management -->
     <tx:annotation-driven />
     <jee:jndi-lookup id="entityManagerFactory"    jndi-name="persistence/zeneJPA" /> 
     <tx:jta-transaction-manager />

的persistence.xml

  <persistence-unit name="ZeneJPA" transaction-type="JTA">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <jta-data-source>jdbc/zeneDS</jta-data-source>
    <properties>
    <property name="hibernate.transaction.manager_lookup_class"    value="org.hibernate.transaction.SunONETransactionManagerLookup"/>
    <property name="hibernate.show_sql" value="true"/>
    <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
    <property name="hibernate.hbm2ddl.auto" value="update"/>
    <property name="hibernate.generate_statistics" value="true"/>
    <property name="hibernate.archive.autodetection" value="class,hbm"/>
    <property name="hibernate.transaction.factory_class" value="org.hibernate.transaction.JTATransactionFactory"/>

保存对象的方法/类

@Repository("AdminDAO")
@Transactional
public class AdminDAOImpl implements AdminDAO {

    @PersistenceContext
    private EntityManager em;


    public void setEntityManager(EntityManager em) {
        this.em = em;
    }

@Override
    public boolean saveCustomer(Customer customer) {
         boolean saved = false;
            try {
                if (customer.getId() == null) {
                    this.em.persist(customer);
                }
                else {
                    this.em.merge(customer);
                }
                saved = true;
            }
            catch (Exception p) {
                saved = false;
                return saved;
            }
            return saved;
    }
}

请帮帮我,我做错了什么? 此配置生成表,但不提交事务。 当我逐步使用degugger时,它实际上调用了save但是没有提交事务。 请问春季交易与Glassfish合作的适当配置是什么?谢谢,我感谢所有的帮助。

0 个答案:

没有答案