我有使用JPA(Hibernate 4.2)的Web应用程序,JavaEE 7在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);
}
}
答案 0 :(得分:1)
@Transactional
。对于WebSphere 8.5.5,您必须将其包装在无状态EJB中。添加@Stateless
代替@Transactional
,它应该有效。 WebSphere支持Web模块中的EJB,因此您不必创建单独的EJB模块。