HIbernate 4.2 PuId 没有活动事务

HIbernate 4.2 No active transaction for PuId

我有一个带有 JPA (Hibernate 4.2)、JavaEE 7 的 Web 应用程序,它在 WebSphere 8.5 上 运行。我想避免在我的应用程序中使用 EJB。当我尝试保留更改时,我得到 javax.persistence.TransactionRequiredException: PuId 没有活动事务。我希望 websphere 能够管理事务。在 Wildfly 8.0 上一切正常。

我的persistence.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>

class 我试图坚持更改的地方:

    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 模块。