persistence@glassfish.java.net

Re: Not cascading remove

From: Wonseok Kim <guruwons_at_gmail.com>
Date: Tue, 25 Mar 2008 21:23:22 +0900

Hi Dru,

When I retested cascaded remove with Order and Item entities which are
similar to yours, there was no problem.
I guess there is something missing in your code. Could you explain your code
in more detail and tell us what version you're using.

BTW, you should see normally working logs like below.

[TopLink Finer]: 2008.03.25
09:10:11.618--ServerSession(1012673)--Thread(Thread[main,5,main])--client
acquired
[TopLink Finest]: 2008.03.25
09:10:11.629--UnitOfWork(12376621)--Thread(Thread[main,5,main])--Execute
query DoesExistQuery()
*[TopLink Finest]: 2008.03.25
09:10:11.630--UnitOfWork(12376621)--Thread(Thread[main,5,main])--PERSIST
operation called on: jpatest.Order_at_67064.
*[TopLink Finer]: 2008.03.25
09:10:11.633--ClientSession(1043272)--Connection(10884088)--Thread(Thread[main,5,main])--begin
transaction
[TopLink Finest]: 2008.03.25
09:10:11.634--ClientSession(1043272)--Thread(Thread[main,5,main])--Execute
query DataModifyQuery()
[TopLink Fine]: 2008.03.25
09:10:11.635--ClientSession(1043272)--Connection(10884088)--Thread(Thread[main,5,main])--UPDATE
SEQUENCE SET SEQ_COUNT = SEQ_COUNT + ? WHERE SEQ_NAME = ?
    bind => [50, SEQ_GEN]
[TopLink Finest]: 2008.03.25
09:10:11.643--ClientSession(1043272)--Thread(Thread[main,5,main])--Execute
query ValueReadQuery()
[TopLink Fine]: 2008.03.25
09:10:11.644--ClientSession(1043272)--Connection(10884088)--Thread(Thread[main,5,main])--SELECT
SEQ_COUNT FROM SEQUENCE WHERE SEQ_NAME = ?
    bind => [SEQ_GEN]
[TopLink Finest]: 2008.03.25
09:10:11.651--ClientSession(1043272)--Connection(10884088)--Thread(Thread[main,5,main])--local
sequencing preallocation for SEQ_GEN: objects: 50 , first: 1, last: 50
[TopLink Finer]: 2008.03.25
09:10:11.653--ClientSession(1043272)--Connection(10884088)--Thread(Thread[main,5,main])--commit
transaction
[TopLink Finest]: 2008.03.25
09:10:11.656--ServerSession(1012673)--Connection(10884088)--Thread(Thread[main,5,main])--local
sequencing preallocation is copied to preallocation after transaction commit
[TopLink Finest]: 2008.03.25
09:10:11.657--UnitOfWork(12376621)--Thread(Thread[main,5,main])--assign
sequence to the object (1 -> jpatest.Order_at_67064)
[TopLink Finest]: 2008.03.25
09:10:11.662--UnitOfWork(12376621)--Thread(Thread[main,5,main])--Execute
query DoesExistQuery()
*[TopLink Finest]: 2008.03.25
09:10:11.663--UnitOfWork(12376621)--Thread(Thread[main,5,main])--PERSIST
operation called on: jpatest.Item_at_b03be0.
*[TopLink Finest]: 2008.03.25
09:10:11.664--UnitOfWork(12376621)--Thread(Thread[main,5,main])--assign
sequence to the object (2 -> jpatest.Item_at_b03be0)
[TopLink Finest]: 2008.03.25
09:10:11.667--UnitOfWork(12376621)--Thread(Thread[main,5,main])--Execute
query DoesExistQuery()
*[TopLink Finest]: 2008.03.25
09:10:11.674--UnitOfWork(12376621)--Thread(Thread[main,5,main])--PERSIST
operation called on: jpatest.Item_at_113a53d.
*[TopLink Finest]: 2008.03.25
09:10:11.681--UnitOfWork(12376621)--Thread(Thread[main,5,main])--assign
sequence to the object (3 -> jpatest.Item_at_113a53d)
[TopLink Finer]: 2008.03.25
09:10:11.693--ClientSession(1043272)--Connection(20358204)--Thread(Thread[main,5,main])--begin
transaction
[TopLink Finest]: 2008.03.25
09:10:11.693--UnitOfWork(12376621)--Thread(Thread[main,5,main])--Execute
query InsertObjectQuery(jpatest.Item_at_113a53d)
[TopLink Finest]: 2008.03.25
09:10:11.695--UnitOfWork(12376621)--Thread(Thread[main,5,main])--Assign
return row DatabaseRecord(
    TEST_ITEM.ITEM_VERSION => 1)
*[TopLink Fine]: 2008.03.25
09:10:11.696--ClientSession(1043272)--Connection(20358204)--Thread(Thread[main,5,main])--INSERT
INTO TEST_ITEM (ID, NAME, ITEM_VERSION, DESCRIPTION) VALUES (?, ?, ?, ?)
    bind => [3, Ballpen, 1, Ballpen]
*[TopLink Finest]: 2008.03.25
09:10:11.712--UnitOfWork(12376621)--Thread(Thread[main,5,main])--Execute
query InsertObjectQuery(jpatest.Item_at_b03be0)
[TopLink Finest]: 2008.03.25
09:10:11.712--UnitOfWork(12376621)--Thread(Thread[main,5,main])--Assign
return row DatabaseRecord(
    TEST_ITEM.ITEM_VERSION => 1)
*[TopLink Fine]: 2008.03.25
09:10:11.713--ClientSession(1043272)--Connection(20358204)--Thread(Thread[main,5,main])--INSERT
INTO TEST_ITEM (ID, NAME, ITEM_VERSION, DESCRIPTION) VALUES (?, ?, ?, ?)
    bind => [2, Pencil, 1, Pencil]
*[TopLink Finest]: 2008.03.25
09:10:11.715--UnitOfWork(12376621)--Thread(Thread[main,5,main])--Execute
query InsertObjectQuery(jpatest.Order_at_67064)
[TopLink Finest]: 2008.03.25
09:10:11.716--UnitOfWork(12376621)--Thread(Thread[main,5,main])--Assign
return row DatabaseRecord(
    TEST_ORDER.ORDER_VERSION => 1)
*[TopLink Fine]: 2008.03.25
09:10:11.717--ClientSession(1043272)--Connection(20358204)--Thread(Thread[main,5,main])--INSERT
INTO TEST_ORDER (ORDER_ID, SHIP_ADDR, ORDER_VERSION, QUANTITY) VALUES (?, ?,
?, ?)
    bind => [1, null, 1, 0]
*[TopLink Finest]: 2008.03.25
09:10:11.728--UnitOfWork(12376621)--Thread(Thread[main,5,main])--Execute
query DataModifyQuery()
*[TopLink Fine]: 2008.03.25
09:10:11.735--ClientSession(1043272)--Connection(20358204)--Thread(Thread[main,5,main])--INSERT
INTO TEST_ORDER_TEST_ITEM (items_ID, Order_ORDER_ID) VALUES (?, ?)
    bind => [2, 1]
*[TopLink Finest]: 2008.03.25
09:10:11.751--UnitOfWork(12376621)--Thread(Thread[main,5,main])--Execute
query DataModifyQuery()
*[TopLink Fine]: 2008.03.25
09:10:11.751--ClientSession(1043272)--Connection(20358204)--Thread(Thread[main,5,main])--INSERT
INTO TEST_ORDER_TEST_ITEM (items_ID, Order_ORDER_ID) VALUES (?, ?)
    bind => [3, 1]
*[TopLink Finer]: 2008.03.25
09:10:11.755--UnitOfWork(12376621)--Thread(Thread[main,5,main])--begin
unit of work commit
[TopLink Finer]: 2008.03.25
09:10:11.768--ClientSession(1043272)--Connection(20358204)--Thread(Thread[main,5,main])--commit
transaction
[TopLink Finer]: 2008.03.25
09:10:11.771--UnitOfWork(12376621)--Thread(Thread[main,5,main])--end
unit of work commit
[TopLink Finer]: 2008.03.25
09:10:11.771--UnitOfWork(12376621)--Thread(Thread[main,5,main])--resume
unit of work
[TopLink Finer]: 2008.03.25
09:10:11.773--ServerSession(1012673)--Thread(Thread[main,5,main])--client
acquired
[TopLink Finest]: 2008.03.25
09:10:11.774--UnitOfWork(28259286)--Thread(Thread[main,5,main])--Merge
clone with references jpatest.Order_at_67064
[TopLink Finest]: 2008.03.25
09:10:11.778--UnitOfWork(28259286)--Thread(Thread[main,5,main])--Register
the existing object jpatest.Item_at_c5495e
[TopLink Finest]: 2008.03.25
09:10:11.779--UnitOfWork(28259286)--Thread(Thread[main,5,main])--Register
the existing object jpatest.Item_at_2af081
[TopLink Finer]: 2008.03.25
09:10:11.786--ClientSession(1043272)--Thread(Thread[Finalizer,8,system])--client
released
*[TopLink Finest]: 2008.03.25
09:10:11.786--UnitOfWork(28259286)--Thread(Thread[main,5,main])--The
remove operation has been performed on: jpatest.Order_at_16c9867
[TopLink Finest]: 2008.03.25
09:10:11.787--UnitOfWork(28259286)--Thread(Thread[main,5,main])--The
remove operation has been performed on: jpatest.Item_at_1ce784b
[TopLink Finest]: 2008.03.25
09:10:11.787--UnitOfWork(28259286)--Thread(Thread[main,5,main])--The
remove operation has been performed on: jpatest.Item_at_c79809
*[TopLink Finer]: 2008.03.25
09:10:11.787--UnitOfWork(28259286)--Thread(Thread[main,5,main])--begin
unit of work commit
[TopLink Finer]: 2008.03.25
09:10:11.789--ClientSession(19432672)--Connection(213274)--Thread(Thread[main,5,main])--begin
transaction
[TopLink Finest]: 2008.03.25
09:10:11.789--UnitOfWork(28259286)--Thread(Thread[main,5,main])--Execute
query DeleteObjectQuery(jpatest.Order_at_16c9867)
[TopLink Finest]: 2008.03.25
09:10:11.792--UnitOfWork(28259286)--Thread(Thread[main,5,main])--Execute
query DataModifyQuery()
*[TopLink Fine]: 2008.03.25
09:10:11.793--ClientSession(19432672)--Connection(213274)--Thread(Thread[main,5,main])--DELETE
FROM TEST_ORDER_TEST_ITEM WHERE (Order_ORDER_ID = ?)
    bind => [1]
[TopLink Fine]: 2008.03.25
09:10:11.805--ClientSession(19432672)--Connection(213274)--Thread(Thread[main,5,main])--DELETE
FROM TEST_ORDER WHERE ((ORDER_ID = ?) AND (ORDER_VERSION = ?))
    bind => [1, 1]
*[TopLink Finest]: 2008.03.25
09:10:11.853--UnitOfWork(28259286)--Thread(Thread[main,5,main])--Execute
query DeleteObjectQuery(jpatest.Item_at_1ce784b)
*[TopLink Fine]: 2008.03.25
09:10:11.856--ClientSession(19432672)--Connection(213274)--Thread(Thread[main,5,main])--DELETE
FROM TEST_ITEM WHERE ((ID = ?) AND (ITEM_VERSION = ?))
    bind => [2, 1]
*[TopLink Finest]: 2008.03.25
09:10:11.876--UnitOfWork(28259286)--Thread(Thread[main,5,main])--Execute
query DeleteObjectQuery(jpatest.Item_at_c79809)
*[TopLink Fine]: 2008.03.25
09:10:11.877--ClientSession(19432672)--Connection(213274)--Thread(Thread[main,5,main])--DELETE
FROM TEST_ITEM WHERE ((ID = ?) AND (ITEM_VERSION = ?))
    bind => [3, 1]
*[TopLink Finer]: 2008.03.25
09:10:11.879--ClientSession(19432672)--Connection(213274)--Thread(Thread[main,5,main])--commit
transaction
[TopLink Finer]: 2008.03.25
09:10:11.880--UnitOfWork(28259286)--Thread(Thread[main,5,main])--end
unit of work commit
[TopLink Finer]: 2008.03.25
09:10:11.881--UnitOfWork(28259286)--Thread(Thread[main,5,main])--resume
unit of work

Cheers,
-Wonseok

On Tue, Mar 25, 2008 at 11:36 AM, Dru Devore <ddevore_at_duckhouse.us> wrote:

> actually I am calling em.remove(em.merge(order)) now I was under the
> impression that the cascade=CascadeType.ALL indicated that a remove would
> remove all the through the relationship not just the intermediary table.
>
>
> ---
> Dru Devore
>
>
>
> -------- Original Message --------
> Subject: Re: Not cascading remove
> From: Marina Vatkina <Marina.Vatkina_at_Sun.COM>
> Date: Mon, March 24, 2008 5:22 pm
> To: persistence_at_glassfish.dev.java.net
>
> Dru,
>
> Are you calling em.remove(order) or (replace my names with the actual
> ones)
> order.getItems().remove(item)?
>
> If the latter, it only removes the relationships, not the entities.
>
> Regards,
> -marina
>
> Dru Devore wrote:
> > I am using ejb 3.0 with an order table and order item table. Wanting to
> > see how it works allowing it to create the linking table, and actually
> > liking I decided to let it be and worry about more important thing. What
>
> > I have is this
> >
> > order (the main table)
> > order_order_item (the linking table)
> > order_item (the item table)
> >
> > When I do a remove it takes it out ofthe linking table but not out of
> > the order_item table.
> >
> > This is how it looks in the order entity
> >
> > @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
> > private List<OrderItem> orderItemList;
> >
> > It will add them and query them but it does not want to remove them.
> > What am I doing wrong?
> >
> > ---
> > Dru Devore
>
>