-->
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: superclass of generated class the same way Torque does it
PostPosted: Fri Dec 17, 2004 9:00 pm 
Beginner
Beginner

Joined: Fri Dec 17, 2004 8:30 pm
Posts: 20
I'm trying to switch to hibernate from torque. One thing that Torque does is automatically create a superclass that you can add code to.

Specifically, if I have a DVD table in the database then when the java object is created from the xml schema it would create a BaseDVD class that contains all the code and then an empty DVD which derives from BaseDVD.

The upshot is that you can make changes to the xml schema and then run the code generator again and it'll overwrite the BaseDVD class, but it won't overwrite the DVD class. I can add my own methods to the DVD class while still being able to automatically regenerate the base class.

In hibernate I can create a BaseDvd.hbm.xml file and then generate a BaseDvd.java file from it. If I then created a new class that derived from BaseDvd then that would not really be helpful. I wouldn't be able to just do:

Query query = session.getNamedQuery("com.oreilly.hh.dvdsById");
query.setInteger("id", id);
Dvd found = (Dvd)query.uniqueResult();

I'd have to do something like:

Query query = session.getNamedQuery("com.oreilly.hh.dvdsById");
query.setInteger("id", id);
BaseDvd found = (BaseDvd)query.uniqueResult();
Dvd dvd = new Dvd(found);

which would just be silly because I'd have to write a ton of special code that copies the BaseDvd into my own Dvd. And then I'd lose all kinds of functionality that I want to keep.

I've looked at the subclass stuff, but it appears to only be used between other hibernate objects that represent actual tables.

Is there a way to do this in hibernate?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 24, 2004 10:21 pm 
Beginner
Beginner

Joined: Fri Dec 17, 2004 8:30 pm
Posts: 20
So apparently this capability does not exist?

My choices are apparently:
1. modify the generated class and then never ever run the hibernate code generator for that class ever again.
2. create a wrapper class that contains the generated class and delegates to it.

The latter is probably pointless, so I guess I'll go with the former. I'll just hand code additional columns into the class instead of using the code generator.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 25, 2004 5:26 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
have you looked at hbm2java and its generated-class attribute ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: generated-class is what I want!
PostPosted: Tue Dec 28, 2004 3:39 am 
Beginner
Beginner

Joined: Fri Dec 17, 2004 8:30 pm
Posts: 20
I had seen the generated-class attribute before, but the description I read of it didn't make it sound like it does what it does.

However, since you pointed it out, I figured I'd just try it to see what it did and it does in fact do precisely what I want!

Thanks!


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.