[jboss-user] [EJB 3.0] - Re: IllegalArgumentException on remove

waynebaylor do-not-reply at jboss.com
Sun Aug 5 20:32:33 EDT 2007


try changing the snippet:
 public void destroy (NewsEntity newsEntity)
  | {
  |     em.merge (newsEntity);
  |     if( em.contains (newsEntity))
  |         logger.info ("The Entity is attached to current Persistence Context");
  |     else
  |         logger.error ("Entity is not attached!");
  |         /* throws exception */
  |        em.remove (newsEntity);
  | } 
to something like:
public void destroy (NewsEntity newsEntity)
  | {
  |     NewsEntity managedEntity = em.merge (newsEntity);
  | 
  |     if( em.contains (managedEntity))
  |     {
  |         logger.info ("The Entity is attached to current Persistence Context");
  |     }
  |     else
  |     {
  |         logger.error ("Entity is not attached!");
  |     }
  |     
  |     /* throws exception */
  |     em.remove (managedEntity);
  | } 

the problem is that you should be using the managed object returned by the EntityManager.merge() method.

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

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



More information about the jboss-user mailing list