HIbernate 4.2 PuId没有活动事务



我有一个在WebSphere 8.5上运行的带有JPA(Hibernate 4.2)、JavaEE 7的web应用程序。我想避免在我的应用程序中使用EJB。当我尝试持久化更改时,我会得到javax.persistence.TransactionRequiredException:PuId没有活动事务。我希望websphere能够管理事务。在wildfly 8.0上,一切都很好。

我的持久性.xml

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<persistence version="2.0"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
                                 http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns="http://java.sun.com/xml/ns/persistence">
    <persistence-unit name="org.jbpm.domain" transaction-type="JTA">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <jta-data-source>jdbc/MyApp</jta-data-source>
       <class>Diagram</class>
        <exclude-unlisted-classes>true</exclude-unlisted-classes>
        <properties>
            <property name="hibernate.max_fetch_depth" value="3"/>
            <property name="hibernate.hbm2ddl.auto" value="update" />
            <property name="hibernate.show_sql" value="false" />
            <property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.WebSphereExtendedJtaPlatform" />
            <property name="hibernate.id.new_generator_mappings" value="false"/>
        </properties>
    </persistence-unit>

以及,我正试图将更改持久化:

    import javax.inject.Inject;
    import javax.inject.Named;
    import javax.transaction.Transactional;
    @Transactional
    @Named
    class PersistentAssetStorage {
      @Inject
        private EntityManager em;
         public long saveProcessDefinition(final Diagram diagram) {
         em.persist(diagram);
    }
}

WebSphere 8.5.5不幸地仅兼容Java EE 6(还不是7),因此它不理解@Transactional。对于WebSphere 8.5.5,您必须将其封装在无状态EJB中。添加@Stateless而不是@Transactional,它应该可以工作。WebSphere支持web模块中的EJB,因此您不必创建单独的EJB模块。

最新更新