Yes, this makes since. The I think one of the problems I was having was that I didn't look that closely at the generated code em.merge(order) before I started this thread. It makes since that it wouldn't cascade in the case I was presenting.
I thank everyone for their help on this.
---
Dru Devore
-------- Original Message --------
Subject: Re: Not cascading remove
From: Marina Vatkina <Marina.Vatkina@Sun.COM>
Date: Tue, March 25, 2008 2:00 pm
To: persistence@glassfish.dev.java.net
Dru,
em.merge() replaces the current values (known to the JPA provider) with the ones
that you have in the instance that you pass as the argument. So when you call
em.merge(order_with_all_but_pk_null_fields), you are effectively resetting even
relationship fields to null, i.e. removing all items from the orderItem
relationships.
When you call em.remove() on the result, there are no items to cascade to.
Does it make sense?
thanks,
-marina
Dru Devore wrote:
> I am not sure if I understand correctly.
>
> What I want to happen is this:
> when I remove an order it removes the order and items but stops there.
> The rest of the referenced tables in item are set to no cascading.
>
> What was happening is this:
> when I called remove with only the id populated in the order it would
> delete the order information and the order_order_item reference table
> entries but not the order_item references.
>
> The code read like this:
> em.remove(em.merge(order)) (as produced by NB)
>
> I changed it to query the order first the do the
> em.remove(em.merge(order)) (at this point the em.merge(order) should be
> a no-op. But what this does is populates the references to the items
> which will then be removed.
>
> Is this right?
>
> Also, would it be right to say that if I were to do the em.remove(order)
> with only the id populated that it would remove the whole thing
> correctly and result in what I am wanting.
>
> Basically! if I populate the id in the order I would expect the order
> and all related tables to be removed which I am guessing would happen if
> I didn't leave the NB generated em.merge(order) part. Is that correct?
>
>
>
> ---
> Dru Devore
>
>
> -------- Original Message --------
> Subject: RE: Not cascading remove
> From: "Gordon Yorke" <gordon.yorke@oracle.com>
> Date: Tue, March 25, 2008 10:25 am
> To: "persistence@glassfish.dev.java.net"
> <persistence@glassfish.dev.java
> <mailto:persistence@glassfish.dev.java>.net>
>
> Just to be clear the issue was that the em.merge() call that you
> were using was asking the Provider to update the managed copy and
> set all of the attributes to null or empty collections. This
> pattern will result in removing all persistent data from an Entity
> and is very dangerous.
> --Gordon
>
> -----Original Message-----
> *From:* Dru Devore [mailto:ddevore@duckhouse.us]
> *Sent:* Tuesday, March 25, 2008 10:03 AM
> *To:* persistence@glassfish.dev.java.net
> <mailto:persistence@glassfish.dev.java.net! >
> *Subject:* RE: Not cascading remove
>
> That worked...so this proves it you do learn something new every
> day.
>
> So if you simply populate the id of an entity and delete the
> entity it will not propagate the changes to related tables,
> beyond the first level. That is a good thing to know.
>
>
>
> ---
> Dru Devore
>
>
> -------- Original Message --------
> Subject: RE: Not cascading remove
> From: Dru Devore <ddevore@duckhouse.us>
> Date: Tue, March 25, 2008 9:39 am
> To:
> <mailto:persistence@glassfish.dev.java.net>persistence@glassfish.dev.java.net
> <mailto:persistence@glassfish.dev.java.net>
>
> I know that the order has items because after ! completing
> the operation I can see the items in the database. This may
> be the problem...for testing purposes I simply wrapped the
> session bean with a service and am calling it through NB
> with just the id populated in the object and no query on the
> object before the delete. I am going to attempt to do the
> delete with querying the oject using the id first then delete.
>
>
>
> ---
> Dru Devore
>
>
> -------- Original Message --------
> Subject: RE: Not cascading remove
> From: James Sutherland <jamesssss@yahoo.com>
> Date: Tue, March 25, 2008 9:28 am
> To: <mailto:persistence@glassfish.dev.java.net>
> <mailto:persistence@glassfish.dev.java.net>persistence@glassfish.dev
> <mailto:persistence@glassfish.dev>! .java.net
>
>
> Yes, remove(order) should cascade the cascade delete
> relationship and also
> remove the order's items (not just the join table).
>
> Is an error occurring, or are the OrderItems just not
> deleted? Try setting
> the log level to finest to see what is occurring.
>
> Also does the order that you are merging have any
> OrderItems? Or were they
> all removed, or not serialized, if it is empty, then
> they will not be
> removed.
>
> A workaround (to whatever is occurring) may be to edit
> the mapping using a
> DescriptorCustomizer and set the order's orderItems mapping
> (ManyToManyMapping) to be privateOwned.
>
>
>
> ddevore wrote:
> >
> > actually I am calling em.remove(em.merge(order)) now
> I was under the
> > impression that the cascade=CascadeType.ALL indicated
> that a r! emove would
> > remove all the through the relationship not just t he
> intermediary table.
> >
> > ---
> > Dru! Devore
> >
>
>
> -----
> ---
> http://wiki.eclipse.org/User:James.sutherland.oracle.com
> James Sutherland
> http://www.eclipse.org/eclipselink/
> EclipseLink ,
> http://www.oracle.com/technology/products/ias/toplink/
> TopLink
> Wiki: http://wiki.eclipse.org/EclipseLink EclipseLink ,
> http://wiki.oracle.com/page/TopLink TopLink
> Forums:
> http://forums.oracle.com/forums/forum.jspa?forumID=48
> TopLink ,
> http://www.nabble.com/EclipseLink-f26430.html
> <http://www.nabble.com/EclipseLink-f264! 30.html>
> EclipseLink
> Book: http://en.wikibooks.org/wiki/Java_Persistence
> <http://e%21%20n.wikibooks.org/wiki/Java_Persistence>
> Java Persistence
> --
> View this message in context:
> http://www.nabble.com/Not-cascading-remove-tp16255109p16274773.html
> Sent from the <http://java.net>
> <http://java.net>java.net <http://java.net> - glassfish
> persistence mailing list archive at <http://Nabble.com>
> <http://Nabble.com>Nabble.com <http://Nabble.com>.
>