[jboss-user] [EJB 3.0] - Re: EJB3 PersistanceManager confusion

alexg79 do-not-reply at jboss.com
Wed Nov 1 12:48:32 EST 2006


anonymous wrote : 1) The default value with be '0'. How does the entitymanager.merge differenciate between '0' default and a debtor.setId(0)? 
My guess is that the entity manager disregards the given PK if you have specified a generation strategy. The only other alternative I can think of is that 0 is considered a special value that has the same meaning as null.
I use atomic primary keys in my project. You should always use persist() when you're generating a new entity, and merge() only when updating an existing one.
The difference between persist() and merge() is that merge will look up the existing entity with the given PK, and if it doesn't exist, it will create a new entity, while persist() will not touch existing entities and should throw an exception if an entity with the given PK exists already.


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

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



More information about the jboss-user mailing list