users@glassfish.java.net

Re: Removing entity from OneToMany Bi-Directional collection?

From: <glassfish_at_javadesktop.org>
Date: Wed, 12 Sep 2007 14:10:57 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:
>
> UpdateEntityBean> i =
> theOwningEntityBean.getUpdateEntityBeans().iterator();
>
>
> asNext() )
> {
> return ;
>
> away first
> i.next();
> while ( i.hasNext() )
> {
> i.next();
> i.remove();
> }
>
> 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.

Hi,

What I needed to do as it turns out is a em.remove( em.merge( i.next() ) )
followed by a em.merge( theOwningEntityBean)

This had the desired effect.

S.D.
[Message sent by forum member 'samdoyle' (samdoyle)]

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