-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: cascade save-update doesn't seem to insert
PostPosted: Sat Aug 10, 2013 5:58 pm 
Newbie

Joined: Wed Sep 10, 2008 2:02 pm
Posts: 14
Location: NJ
I am confused. I have just moved code from JBoss 4.2.2 to JBoss 7.1.1. I have a parent-child relationship mapped like this:

<class name="UserMedium" ...>
.
.
.
<set name="mailDelays" inverse="true" cascade="save-update" order-by="dateReported desc" lazy="false">
<key column="usermediumid" not-null="true"/>
<one-to-many class="MailDelay"/>
</set>
.
.
.
</class>

<class name="MailDelay" ...>
.
.
.
<many-to-one name="userMedium" column="usermediumid" not-null="true" lazy="false" fetch="join"/>
.
.
.
</class>

I have a Session Bean whose job it is to decide if the relationship should be persisted. Given a MailDelay with a valid UserMedium reference, it may decide to add the MailDelay to the UserMedium's collection of mail delays, or it may not. If it does, it does this (from within an active Persistence Context) (assume that hbmSession is the EntityManager's delegate):

hbmSession.update(mailDelay.getUserMedium());
mailDelay.getUserMedium().addMailDelay(mailDelay);

and the UserMedium implementation of addMailDelay(MailDelay mailDelay) looks like this:

public void addMailDelay(MailDelay mailDelay) {
getMailDelays().add(mailDelay);
mailDelay.setUserMedium(this);
}

When the transaction commits I see this in the logs:

17:32:48,634 INFO [stdout] (ajp--127.0.0.1-8009-1) Hibernate: update users_media set username=?, mediumid=?, ...... where usermediumid=?

There is no insert into the mail_delays table. This is different from the behavior in 4.2.2. In 4.2.2, it worked as expected, i.e., the new mail delay was added to the mail_delays table.

Can anyone provide some insight?

I'd much appreciate it.

Richard


Top
 Profile  
 
 Post subject: Re: cascade save-update doesn't seem to insert
PostPosted: Mon Aug 12, 2013 3:15 pm 
Newbie

Joined: Wed Sep 10, 2008 2:02 pm
Posts: 14
Location: NJ
I took a careful look to see if I had made any changes to the xml file that describes the UserMedium and found that where I used to have cascade="save-update, all", I now had cascade="save-update". I don't remember removing the "all", but apparently I did. So now that I've put it back, it works as it did in 4.2.2, of which I'm glad. However, I still don't understand it. Why is it not enough to say "save-update"? From the documentation I've read, this should cause transient entities in the owned collection to be persisted.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.