[jboss-user] [JBoss Seam] - Merging objects problems.

sjmenden do-not-reply at jboss.com
Wed Aug 23 17:31:50 EDT 2006


I have a form which a user can input a group name and other group information.  The EJB3 backing the form persists/merges the Injected Group object given there are no errors.  

My Problem:  

First I could not get em.persist(group) to persist more than one Group object after a form submit because of org.hibernate.PersistentObjectException: detached entity passed to persist:....

So, then I started using em.merge(group) on the Group object, which fixed the previous problem, but led to another.  When I am creating two different groups by submitting the form twice with different information, the entity manager appears only update the same group by the console output:

Output after em.merge(group) after the form submit the first time:

  | 16:11:26,634 INFO  [RegisterGroupAction] Registered new Group asdf with id: 4
  | 

Output after em.merge(group) after the form submit the second time with different data.

  | 16:11:41,496 INFO  [RegisterGroupAction] Registered new Group blah with id: 4
  | 

This is not the behavior I want, I want a new Group object to be persisted every time the user submits a new group form, so I should be seeing the id incremented, not staying the same,  how can I do this.



  | @Stateless
  | @Name("registerGroup")
  | public class RegisterGroupAction implements RegisterGroup {
  | 
  |    @In(create=true) @Out @Valid
  |    private Group group;
  | 
  |    @PersistenceContext
  |    private EntityManager em;
  | 
  |    @Logger
  |    private Log log;
  | 
  |    public String register() { 
  |       List existing = em.createQuery("select name from Group where name = :name")
  |          .setParameter("name", group.getName())
  |          .getResultList();
  |       if (existing.size()==0) {
  |          group = em.merge(group);
  | 	//em.persist(group);
  | 				 	 
  | 	FacesMessages.instance().add("Group successfully created");
  |          log.info("Registered new Group #{group.name} with id: " + group.getGroupId());
  | 	return "/showGroup.jsp";
  |       } else {
  |          FacesMessages.instance().add("Group name already exists, please choose another");
  |          return null;
  |       }
  |    }
  | }
  | 

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

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



More information about the jboss-user mailing list