[jboss-user] [EJB 3.0] - Re: Extended Persistence Context and merge()

radl01 do-not-reply at jboss.com
Wed May 16 16:47:35 EDT 2007


As you sead merge is used for detached objects and persist for atached ones. 
Short example for persist (update action)

   EntityManger em;

   .....
  Tab02000 recentRecord = (Tab02000)em.find(Tab02000.class, key);
  .. do some changes to recentRecord
  em.persist(recentRecord);  // in this case JPA will call update action because you are changing existing object

Short example for merge

   EntityManger em;
   Tab02000 newRecord = new Tab02000();
    ... set all values
    em.merge(newRecord);

The second example is BAD PRACTISE of using JPA

Jan
   

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

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



More information about the jboss-user mailing list