-->
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' in UML terms?
PostPosted: Tue Oct 28, 2003 8:48 am 
Senior
Senior

Joined: Tue Oct 21, 2003 8:15 am
Posts: 186
Could someone please explain what inverse='true' means in UML terms? I get really confused about it... but I know I need to know about to get bidirectionality to work for xxx-to-many relations.

Thanks for any hints.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 28, 2003 8:49 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Read the parent/child relationship chapter in the reference documentation.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 28, 2003 8:59 am 
Senior
Senior

Joined: Tue Oct 21, 2003 8:15 am
Posts: 186
i did - still confused. perhaps I'm stupid, or something.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 28, 2003 9:00 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Read it again :)

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 28, 2003 9:23 am 
Senior
Senior

Joined: Tue Oct 21, 2003 8:15 am
Posts: 186
I guess I'm confused about the concept of a "inverse side" when there isn't a natural parent/child concept.

For instance, if I have a Product that can be contained in many ProductGroup's and that the ProductGroups can hold many products, who is the inverse side? In my head, none, yet Hibernate forces me to pick one.

It depends on the use case. Sometimes I want to get a list of products within a product group. Other times I need the product groups that a certain product belongs to.

Hmprf... my head is spinning.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 28, 2003 1:02 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
inverse define who is responsible of the association.
Change made on the side of the inverse="true" are not persisted

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 28, 2003 1:14 pm 
Regular
Regular

Joined: Tue Aug 26, 2003 3:34 pm
Posts: 54
Location: Farroupilha - Brasil
Quote:
inverse define who is responsible of the association.
Change made on the side of the inverse="true" are not persisted



A simple example :

Schema:

User * -------> * Group

table user (id integer)
table group (id integer)
table user_group(user_id integer, group_id integer)

The groups set in User is not inverse, the users set in Group is inverse.

When you delete an User the association in the table user_group is also deleted ... however if you delete a Group the user_group association is not deleted because the users set in Group is inverse = true.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 28, 2003 1:21 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Quote:
yet Hibernate forces me to pick one

Actaully it does not. Maybe you are confusing the issue due to the Parent/Child docs. That doc is just showing how to setup a true parent-child relation. If your "child" can be persisted and referenced outside its assoication with your "parent" than that is not a true parent-child relationship, just a simple one-to-many association.

It is totally valid to to have a collection in Hibernate mapped as inverse="false" (thats why its an option and actually the default). Even for a many-to-many, both sides can be mapped as inverse="false" meaning the association can be manipulated from either end.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 31, 2003 9:16 am 
Senior
Senior

Joined: Tue Oct 21, 2003 8:15 am
Posts: 186
So in UML terms, inverse=true simply mean that the given end of the association is not navigable?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 31, 2003 9:55 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
NO!

inverse="true" deals with SQL insertion/update of the relationship. It has absolutly no link to Object manipulation and navigation.

A(inverse=true) <-many-to-many-> B

means a.getBs().add(b) will not do any SQL insert in the relation table
but means b.getAs().add(a) will do.

As you can see I'm able to navigate from a to b (a.getBs()) and b to a (b.getAs())

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 31, 2003 10:04 am 
Senior
Senior

Joined: Tue Oct 21, 2003 8:15 am
Posts: 186
So what will a.getBs().add(b) do?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 31, 2003 10:09 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Only object level manipulation. No DB, that's the purpose of inverse="true"

Usually, you want to keep your object model consistent so you do the previous order.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 01, 2003 7:14 pm 
Senior
Senior

Joined: Tue Oct 21, 2003 8:15 am
Posts: 186
steve wrote:
It is totally valid to to have a collection in Hibernate mapped as inverse="false" (thats why its an option and actually the default). Even for a many-to-many, both sides can be mapped as inverse="false" meaning the association can be manipulated from either end.


But... the doc says it can't be so, because of constrains violations?? What does this mean?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 03, 2003 12:29 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
After the huge amount of questions on inverse="true", I wrote a small tutorial on the wiki. I probably left some errors. Please read and improve it.
http://www.hibernate.org/155.html

I did not talk about uml., it's intentional ;-)

_________________
Emmanuel


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.