users@glassfish.java.net

Removing entity from OneToMany Bi-Directional collection?

From: <glassfish_at_javadesktop.org>
Date: Wed, 12 Sep 2007 13:59:16 PDT

How do I get the records removed from the db? I have tried removing the entities from the collection and then merge the owning entity but the records are still left in the db.

example:
         
Iterator<UpdateEntityBean> i = theOwningEntityBean.getUpdateEntityBeans().iterator();
         
if ( !i.hasNext() )
{
   return ;
}
         
// Throw away first
i.next();
while ( i.hasNext() )
{
   i.next();
   i.remove();
}
         
em.merge( theOwningEntityBean );

The relationship would be defined something as:
@OneToMany(cascade={CascadeType.ALL}, fetch=FetchType.EAGER, mappedBy = "owningEntity")
@OrderBy( "receivedTime DESC" )

I could create a NamedQuery to do this but I shouldn't have to since the collection is available.
[Message sent by forum member 'samdoyle' (samdoyle)]

http://forums.java.net/jive/thread.jspa?messageID=235127