-->
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.  [ 14 posts ] 
Author Message
 Post subject: inverse=true vs cascade=save-update
PostPosted: Mon Mar 21, 2005 11:15 am 
Newbie

Joined: Tue Feb 22, 2005 4:10 pm
Posts: 19
I am getting confused over and over and the text doesn't seem to be helping...

Take Category class/mapping, for instance.

If inverse=true, as I understood from the book, it means that if I say something like:

category.getChildCategories().add(category);

This will NOT be persisted since I specified that this is a bidirectional relationship and the other end (category.setParent(category)) should be the one persisting the entity.

However, cascade=save-update, if I understood it correctly, says that if I add a category to childCategories, then that Category WILL be persisted.

This doesn't make any sense, so I must be confusing something.

Could you explain please?

Thanks,
NG.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 21, 2005 12:23 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
No, it will not be persisted, because this side will be ignored if you set inverse="true", and forget to the the bidirectional back-pointer on the other side. It's really not that difficult. There is also a very detailed document on the Wiki explaining inverse.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 21, 2005 1:04 pm 
Newbie

Joined: Tue Feb 22, 2005 4:10 pm
Posts: 19
I see.

So, when on page 110, you say:
"Without the inverse attribute, Hibernate would try to execute two different SQL statements, both updating the same foreign key column..."

you mean that this will happen when you end up calling both? i.e.:
session.save(item);
session.save(bid);

So, when calling session.save(item), Hibernate would grab the foreign key out of 'bid' and store it in the ITEM table. Then, when calling session.save(bid), Hibernate would persist 'bid' to BID table, grab its primary key (possibly just out of 'bid' instance) and then update ITEM table with it (as a foreign key)?

Is this correct?

Thanks,
NG.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 21, 2005 1:06 pm 
Newbie

Joined: Tue Feb 22, 2005 4:10 pm
Posts: 19
Oh, yeah...

And same would be true if cascade="save-update" is specified and inverse="false", expect the second call to session.save(bid) would be implicit (Hibernate takes care of this).

Is that correct?

Thanks,
NG.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 21, 2005 1:08 pm 
Newbie

Joined: Tue Feb 22, 2005 4:10 pm
Posts: 19
nistarguy wrote:
Oh, yeah...

And same would be true if cascade="save-update" is specified and inverse="false", expect the second call to session.save(bid) would be implicit (Hibernate takes care of this).

Is that correct?

Thanks,
NG.


CORRECTION:
SAID: "second call to session.save(bid) would be implicit"

SHOULD HAVE BEEN: "second call, session.save(bid), would be implicit"


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 21, 2005 1:17 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Cascade controls transitive state changes.

Inverse works at a lower level, it controls which side will be used to actually build the SQL statements.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 21, 2005 1:23 pm 
Newbie

Joined: Tue Feb 22, 2005 4:10 pm
Posts: 19
christian wrote:
Cascade controls transitive state changes.

Inverse works at a lower level, it controls which side will be used to actually build the SQL statements.


Yes, I've read this in your book. Obviously, these generic statements don't translate for me 100% into practice.

Could you answer my previous questions then? Was my understanding, as I described it, not correct?

Thanks,
NG.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 21, 2005 1:25 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Sure, why not. Please continue this discussion in the regular user forum.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 22, 2005 11:00 am 
Newbie

Joined: Tue Feb 22, 2005 4:10 pm
Posts: 19
christian wrote:
Sure, why not. Please continue this discussion in the regular user forum.


Christian,

I have posted my question to the regular user forum, but haven't gotten a response from anyone...

Would you be able to answer my original question either here or in that forum:
http://forum.hibernate.org/viewtopic.php?t=940245

Thanks,
NG.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 22, 2005 11:56 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
I'm sorry, but I can't give personal trainings...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 24, 2005 3:46 pm 
Newbie

Joined: Tue Feb 22, 2005 4:10 pm
Posts: 19
christian wrote:
I'm sorry, but I can't give personal trainings...


It boggles my mind why you would be continuously nasty to me, while I keep ignoring your self-righteous annoyance and move on to the technical stuff anyway. (This is not the first post this is happening.)

You could have at least answered a yes/no question with a "no" without giving me an explanation. I can see now that answering my questions for such a huge expert as yourself is too much for you.

I was also not aware that "Authors Online" of Manning really meant that you are here online to tell me to take a hike. After all, I WAS asking you to explain what it states in your book. That's what Authors online is for! It's not there for you to tell me that the book already explained it all and if I didn't understand it, that's just too bad.

I started looking through other posts and see that your terse, condescending, "I am an expert and you are not and you will stay that way" attitude is showing through in quite a number of them.

Fine. So, you have a personality problem. I'll leave you to your problems and move on. It's just that some people are bigger than technology as people. Some people are smaller. Obviously, your expertise is seriously getting to your head.

Good luck with that,
NG.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 24, 2005 5:31 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
I've answered your question with "Yes, why not. It sure works like this." Sorry if this was too implicit.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 24, 2005 5:34 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
P.S. I know it can be frustrating to learn something in a short time, and it looks to me like you are trying to read and digest the book too quickly. Some of this stuff isn't obvious the first time you read it, but I don't know how to explain it different or better than I already have. Maybe others in the forum can...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 24, 2005 6:34 pm 
Newbie

Joined: Tue Feb 22, 2005 4:10 pm
Posts: 19
christian wrote:
I've answered your question with "Yes, why not. It sure works like this." Sorry if this was too implicit.


Christian,

I am terribly sorry if all this was just a big misunderstanding. I thought you were saying "Sure, why not" I'll answer your question, just move it to the regular user forum. I did that and...

Perhaps, I am just misunderstanding your style of writing in this forum. Since I am no longer sure I was understanding you, please accept my apologies for the frustrated post before. I was obviously misunderstanding you to be saying that you're refusing to answer a yes/no question.

In the end, thanks for actually (as it turns out) answering my question.

Sincerely,
NG.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 14 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.