我正在研究Seam到CDI的迁移。对于数据库事务,我使用的是Deltaspike,Javaee6。我遵循了Deltaspike中给出的JTA文件中的指示。
的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="XXXX" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:jboss/datasources/jdbc/XXXX</jta-data-source>
<properties>
<!-- property name="hibernate.hbm2ddl.auto" value="validate"/ -->
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider"/>
<property name="hibernate.cache.use_query_cache" value="false"/>
<!-- property name="hibernate.cache.use_second_level_cache" value="false"/-->
<property name="hibernate.show_sql" value="false"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
</properties>
ResourceProducer.java
@PersistenceUnit(unitName="XXXX")
private EntityManagerFactory entityManagerFactory;
@Produces
@Default
@RequestScoped
public EntityManager create()
{
return this.entityManagerFactory.createEntityManager();
}
public void dispose(@Disposes @Default EntityManager entityManager)
{
if (entityManager.isOpen())
{
entityManager.close();
}
}
我正在尝试使用Deltaspike中的@Transactional注释将值存储到数据库中。我没有看到任何错误,但价值没有存储在数据库中。
@Named("accountDetailsAction")
@ConversationScoped
public class AccountDetailsAction implements Serializable {
@Inject
private EntityManager entityManager;
...
@Transactional
public void saveAccountComment() throws SystemException {
System.out.println("Entered into saveAccountComments method...");
Account acct = acctInfo.getAccount();
acct.setComment(accountForm.getCommentText());
Date lastEdited = new Date();
acct.setCommentLastEdited(lastEdited);
Officer lastEditor = utils.getOfficer();
acct.setCommentLastEditorEmployeeId(lastEditor.getEmployeeId());
accountForm.setLastEditDate(lastEdited);
accountForm.setLastEditor(lastEditor.getEmpIdAndFullName());
}
任何人都面临同样的问题?你能指导我解决这个问题吗?我有没有错过任何配置。
答案 0 :(得分:1)
Didi您尝试在beans.xml中启用它
<?xml version="1.0" encoding="UTF-8"?>
<beans bean-discovery-mode="all" version="1.1"
xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd">
<interceptors>
<class>org.apache.deltaspike.jpa.impl.transaction.TransactionalInterceptor</class>
</interceptors>
</beans>