3 Replies Latest reply on Nov 26, 2007 9:22 AM by sefai

    Seam remoting and persistence

    tamirw

      I'm just starting to play with Seam remoting, and I'm having the following problem with persistence :

      My POJO actions are able to query the DB just fine, but when trying to create a new entity instnace, the persist() method seems to return without doing anything in the DB.

      I'm attaching the relevant code, persistence.xml and components.xml.

      Any help would be greatly appreciated.

      persistence.xml
       <persistence-unit name="Iou" transaction-type="JTA">
       <provider>org.hibernate.ejb.HibernatePersistence</provider>
       <jta-data-source>java:/IouDatasource</jta-data-source>
       <properties>
       <!--
       <property name="hibernate.hbm2ddl.auto" value="${hibernate.hbm2ddl.auto}"/>
       -->
       <property name="hibernate.hbm2ddl.auto" value="update" />
       <property name="hibernate.show_sql" value="true" />
       <property name="hibernate.transaction.manager_lookup_class"
       value="org.hibernate.transaction.JBossTransactionManagerLookup" />
      
       </properties>
      
       </persistence-unit>


      components.xml
       <core:managed-persistence-context auto-create="true"
       entity-manager-factory="#{IouEntityManagerFactory}" name="entityManager"/>
       <core:entity-manager-factory name="IouEntityManagerFactory" persistence-unit-name="Iou"/>
      


      RegisterAction.java
      package com.iou.action;
      
      import java.util.List;
      
      import javax.persistence.EntityManager;
      import javax.persistence.PersistenceContext;
      
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Logger;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Out;
      import org.jboss.seam.annotations.Transactional;
      import org.jboss.seam.annotations.WebRemote;
      import org.jboss.seam.core.FacesMessages;
      import org.jboss.seam.log.Log;
      import org.jboss.seam.security.Identity;
      
      import com.iou.entity.User;
      
      @Name("register")
      public class RegisterAction {
      
       @Out
       private User currentUser;
      
       @In
       private EntityManager entityManager;
      
       @Logger
       Log log;
      
       @WebRemote
       public User register(String email, String password, String name) {
       User newUser = null;
       List existing = entityManager.createQuery(
       "select u from User u where u.email=:email").setParameter(
       "email", email).getResultList();
       if (existing.size() == 0) { // the query is executed just fine
       newUser = new User();
       newUser.setEmail(email);
       newUser.setPassword(password);
       newUser.setName(name);
       newUser.setActive(true);
       entityManager.persist(newUser); //nothing is saved to the DB.
       currentUser = newUser;
       return newUser;
       } else {
       User existingUser = (User) existing.get(0);
       if (existingUser.isActive() == false) {
       existingUser.setActive(true);
       log.info("User " + email + " has been activated");
       currentUser = existingUser;
       return existingUser;
       } else {
       log.info("email " + email + " already exists");
       return null;
       }
       }
      
       }
      }
      


        • 1. Re: Seam remoting and persistence
          shane.bryzak

          I actually had the same problem with web service requests, but I can't remember how I fixed it. Could you please raise this in JIRA and assign to me, I'll try to get it addressed before the CR2 release.

          • 2. Re: Seam remoting and persistence
            tamirw

            Thanks for the reply !

            I will, but before I do, maybe this piece of info would help :
            When I switched to using EJB SLSB as actions, the problem went away. There seems to be something wrong (or mis-configured) with the replacement of the container-managed transactions. Even though I think I've configured everything to work with seam-managed transactions and seam-managed persistence, it didn't work till I switch to EJB3.

            Makes sense ?

            • 3. Re: Seam remoting and persistence

              shane, I have the same problem using POJO web service. Could you please try to remember how you fixed it?