我一直在尝试在 JBoss 中将 Vaadin JPAContainer 与 JTA 数据源一起使用,但在提交 FieldGroup 时我不断收到此错误:“没有正在进行的事务”
这是我的persistence.xml
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="Pagamento">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:jboss/datasources/Pagamento</jta-data-source>
<class>br.com.edu.entidades.Usuario</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"></property>
<property name="hibernate.cache.use_second_level_cache" value="false"></property>
<property name="hibernate.hbm2ddl.auto" value="update"></property>
<property name="hibernate.show_sql" value="false"></property>
<property name="hibernate.format_sql" value="true"></property>
</properties>
</persistence-unit>
</persistence>
我还使用自定义 EntityProvider 来支持 JTA:
public class EduEntityProvider extends MutableLocalEntityProvider<Usuario> {
private EntityManager em = HibernateUtils.entityManager;
public EduEntityProvider() {
super(Usuario.class);
setEntityManager(em);
setEntitiesDetached(false);
setTransactionsHandledByProvider(false);
}
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
protected void runInTransaction(Runnable operation) {
super.runInTransaction(operation);
}
}
实体:
@SuppressWarnings("serial")
@Entity
@Table(name="usuario")
public class Usuario extends EduPersistentEntity {
@Id
@Column(name="id")
@VisivelTabela(false)
private String id;
@Column(name="nome")
private String nome;
@Column(name="email")
private String email;
@Column(name="senha")
private String senha;
@Column(name="matricula", unique=true)
private String matricula;
gets...
sets...
}
如果我将提供者处理的事务设置为 true
"setTransactionsHandledByProvider(false);", i'll get the error
" A JTA EntityManager cannot use getTransaction()".
如果有人可以向我指出一个工作示例,或者只是给我一个关于我做错了什么的提示,将不胜感激。