[jboss-user] [EJB/JBoss] - EntityManager merge and the seam-registration example.

hchafi do-not-reply at jboss.com
Fri Jul 21 01:04:42 EDT 2006


I have a question about merge and persist. I understand the basic difference between the two, but I am trying to undertand a bit more of the behavior of merge.

I modified the User.java class in the seam-registration example and added an Id field.


  |        @Id @GeneratedValue(strategy=GenerationType.AUTO)
  | 	public Long getId() {
  | 		return id;
  | 	}
  | 

The problem I ran into is the "detached entity passed to persist" as I was trying to register multiple users. I guess persist expects the id field not to be set. At least that is what I gathered from other posts.

I switched to merge, and it works. I don't understand why it should work though. Since User is a session scoped entity bean, doesn't it mean it should remain alive during the whole session. in which case shouldn't the merge just update the same user instead of creating a new one. I inspected the database, and it does indeed create multiple users. 

Can someone point to the hole in my understanding.

-hc

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

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



More information about the jboss-user mailing list