1

I am working on Seam to CDI migration. For database transaction I am using Deltaspike, Javaee6. I have followed the instruction given in the Deltaspike with JTA document.

Deltaspike with 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();
    }
}

I am trying to store the value into database using @Transactional annotation in Deltaspike. I haven't seen any errors but the value is not stored in the database.

@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());
}

Anyone have faced the same issue? Can you please guide me to fix this issue? Is there any configuration I have missed.

Sudha
  • 220
  • 2
  • 16
  • There isn't enough information in this question. If the value isn't stored in the database, have you traced back to see if the expected methods are being called? Is the EntityManager being injected? Are you catching and squelching exceptions? Does it work if you use EJB instead of CDI (just change annotations)? – DavidS Apr 22 '16 at 18:40
  • David, Than you for the response. I have added the method details in the question also it prints the value in the console. So I am sure the method got called. For the annotation I am using Deltaspike Transactional, import org.apache.deltaspike.jpa.api.transaction.Transactional; – Sudha Apr 22 '16 at 18:47
  • Good update, but I don't see that you ever use your `entityManager` in `saveAccountComment`. Has it been successfully injected (not null)? Where are you getting `acctInfo` from? Are you familiar with usage of `EntityManager`? – DavidS Apr 22 '16 at 18:50
  • David, Than you for your help and proper response. The class where I have tested that is very big one. I have tested in other place it is working fine. @Transactional is working. Thanks again !!! – Sudha Apr 22 '16 at 19:07
  • No worries, glad you've figured it out. Thanks for letting me know. – DavidS Apr 22 '16 at 19:11

1 Answers1

1

Didi You try to enable it in 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>
Igor Vuković
  • 742
  • 12
  • 25