-->
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.  [ 4 posts ] 
Author Message
 Post subject: Can Middlegen be told to ignore composite keys?
PostPosted: Tue Oct 26, 2004 9:02 pm 
Newbie

Joined: Tue Oct 19, 2004 3:22 pm
Posts: 6
Location: Mobile, RV
Hello,

I am using Middlegen R5. Composite keys are a real pain. In many cases they are not needed, for example when the is an auto incrementing part. I am dealing with a large legacy (Oracle) database that cannot be changed. Is there a way to tell Middlegen NOT to generate composite keys at all? I know I can manually edit the xml files but there are over a hundred and the assosiations are as hard to track down as the keys themselves.

Thanks and good job!
Tim


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 27, 2004 7:54 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Yes composite keys are a pain. It also sounds like your database schema is not a good one. Currently there is no way to turn off composite key generation - not practical anyway - how do you automatically determine an appropriate key. Anyway, since you have your own rules for key selection, I would suggest you edit a copy of the velocity script. The composite key sections are obvious (and makes up a large portion of the script). This way you only edit one file rather than all of the hbm's.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 28, 2004 4:18 pm 
Newbie

Joined: Tue Oct 19, 2004 3:22 pm
Posts: 6
Location: Mobile, RV
I agree. My fix though was to write my own sequence generator but not as a sub class of hibernate's. I figured that since I have to invoke the generator myself I might as well decouple it.

So I ended up with:

.....Java code frag
seqGenerator sgen = new seqGenerator();

hibObj.City city = new hibObj.City();
sgen.setId(city); // sets sequential id from sequence in oracle
hibernateUtil.currentSession().save(city);

seqGenerator.setId() figures out the sequence name and the name of the id method ("set" + classname + "Id") and sets the value returned from the call to the sequence, always a Long.

It also knows how to handle composit id objects (classname + "PK") -- this is the evil thing that started all of this!

I can also run setId() on a any object whether or not it has a sequence associated with it.

I wrote and tested all of it in 1 day. Much faster than the alternative which was going to be a Perl script to add all of the <generator> stuff to the (100+) hbm.xml files and the hibernate specific generator for composites.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 28, 2004 9:42 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Cool. Nice work.


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