[jboss-user] [JBoss Seam] - Seam remoting and persistence

tamirw do-not-reply at jboss.com
Sat Sep 29 17:04:20 EDT 2007


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;
  | 			}
  | 		}
  | 
  | 	}
  | }
  | 

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4089987#4089987

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4089987



More information about the jboss-user mailing list