-->
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.  [ 10 posts ] 
Author Message
 Post subject: Design OK?
PostPosted: Mon Nov 03, 2003 9:31 am 
Senior
Senior

Joined: Tue Oct 21, 2003 8:15 am
Posts: 186
OK, after turning my brain inside out a few days, I've got my Rational Rose-to-Hibernate-mapping generator going.

Although I loose some control over the mapping, I think it works pretty well.

This is what I do:

1) Whenever the UML has an attribute/field, I map it to property. If the field is an array, I map it to a set (using one-to-many if it is an array of other classes).

2) For associations, I always use set - NEVER list, bag, etc. I use stereotype so that the modeller can decide what side is inverse, if any. Sounds OK?

3) I generate the mapping file so that all ID's are surrogate hilo keys.

4) If the association is marked as "aggregate" or "composite", I add a 'cascade=all'

So I always use <set> for collections and many-to-many and one-to-many relationsships.

This should be OK since I use surrogate keys, right? (which are never equal to one another)

What do you think? Will I get into trouble with such a generator? My goal is to avoid hacking mapping XML - just change the ROSE model and push 'regenerate'...


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 03, 2003 12:25 pm 
Regular
Regular

Joined: Tue Sep 16, 2003 11:35 am
Posts: 93
Location: San Francisco, CA
looks good to me!

if you have two tables, one has a foreign key pointing to the other's PK, this relationship can always be modeled with a one-to-many set

if you have a join table, and each record (fk1,fk2) is unique, this relationship can always be modeled with a many-to-many set


Top
 Profile  
 
 Post subject: Re: Design OK?
PostPosted: Mon Nov 03, 2003 12:36 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
nickvajberg wrote:
2) For associations, I always use set - NEVER list, bag, etc. I use stereotype so that the modeller can decide what side is inverse, if any. Sounds OK?
Quote:
Can't you use a stereotype for that ?

nickvajberg wrote:
4) If the association is marked as "aggregate" or "composite", I add a 'cascade=all'

Hum, you will loose lots of control if you cannot set lazy and cascade. These are essential elements of optimization in Hibernate, and cannot be guessed.

nickvajberg wrote:
My goal is to avoid hacking mapping XML - just change the ROSE model and push 'regenerate'...

Why don't you use xdoclet hibernate tags ?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 04, 2003 3:21 am 
Senior
Senior

Joined: Tue Oct 21, 2003 8:15 am
Posts: 186
Quote:
Can't you use a stereotype for that


Yes, by stereotyping the association. Using set for now, appears that I don't gain much by supporting bags and lists when using surrogate keys.

Quote:
Hum, you will loose lots of control if you cannot set lazy and cascade


I know, but we can probably solve this using stereotypes and tagged values.

Quote:
Why don't you use xdoclet hibernate tags?


1) Because we generate source code files from the mapping document

2) Because xdoclet really doesn't abstract the mapping process that much.

The points is: we have a domainmodel i Rose and don't wanna touch it again after pressing the generate button.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 04, 2003 10:43 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
nickvajberg wrote:
Yes, by stereotyping the association. Using set for now, appears that I don't gain much by supporting bags and lists when using surrogate keys.

hibernate can add items on bags and lists wo loading the whole collection.
http://www.hibernate.org/117.html#A8

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 04, 2003 10:55 am 
Senior
Senior

Joined: Tue Oct 21, 2003 8:15 am
Posts: 186
Are you saying that if I use <set>, the entire set is loaded before adding new items? That's horrible!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 04, 2003 10:56 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
_with_out_

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


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 04, 2003 10:58 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Quote:
Are you saying that if I use <set>, the entire set is loaded before adding new items? That's horrible!


So how exactly do you propose to calculate the return value of java.util.Set.add(), if you don't know what elements exist in the collection?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 04, 2003 3:58 pm 
Senior
Senior

Joined: Tue Oct 21, 2003 8:15 am
Posts: 186
OK --- so <map> is a more reasonable choice?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 05, 2003 12:04 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Hum, depends.
Quote:
Large Hibernate bags mapped with inverse="false" are inefficient and should be avoided; Hibernate can't create, delete or update rows individually, because there is no key that may be used to identify an individual row.

Note that the update performance of an <idbag> is much better than a regular <bag>! Hibernate can locate individual rows efficiently and update or delete them individually, just like a list, map or set.


So idbag is a more reasonable choice ?
No, It depends of your collection semantic (ordered or not, unique or not, indexed or not, ...). IMO, it must stay in control of the developer.

_________________
Emmanuel


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