-->
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: How can I cutomize hibernate artifact generation POJOs?
PostPosted: Fri Dec 16, 2005 7:38 pm 
Newbie

Joined: Tue Aug 02, 2005 5:04 pm
Posts: 15
Hibernate version:
HibernateTools-3.1.0.beta2

I have table names of table1, table2 and I'd like to generate POJO class names of table1DTO table2DTO.

Also I'd like to generate a business object class for each POJO class named table1BOParent and table2BOParent for example with each one invoking the corresponding DAO class. Then *whew* I'd like to generate a blank business object stub table1BO, table2BO inheriting from the business object class. These *BO classes wouldnt be generated if one already exists. That way I could override the business object without having to worry about the automatically generated files clobbering my changes.

Are these things easily done, if so where can I look for more information? I was able to override dao/daohom.vm and pojo/*.vm. But it didn't seem quite useful. I think the declaration name needs to have "DTO" appended to it for POJOs but not for DAO's / business objects.

Thanks for any help.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 17, 2005 5:13 am 
Beginner
Beginner

Joined: Fri Nov 04, 2005 3:51 pm
Posts: 32
I don't think hbm2java does this anymore.

Here how I do it:
I created an xsl stylesheet that transforms the mapping.hbm file into a file to be used by hbm2java.
The transformation forces all the classes down into a subclass of itself. Its superclass gets renamed to Base + ClassName. That's pretty much all it does, and pretty much leaves everything else intact (there are some weird things that happend due to DTD. I'll fill you in on if you want to try it).
The output file is used by hbm2java. So for each class you initially started out with, you end with a 'Base' class that has all the bean properties and a subclass that is empty ("business class").
I generate the classes in an Ant task, but I have to perform some trickery there to get it to no overwrite my business classes... so I am free to edit those without worrying about the persistent properties.

Anyway, it's a whole process. If you want to try it out, let me know if you have more questions.

That generated file is only for use by hbm2java. The original mapping file is the one used by Hibernate at run time.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 17, 2005 12:42 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
hbm2java can be extended with this but noone have yet contributed the functionallity.

I always use <meta name="generated-class">MyWhateverBase</meta> to handle this case.

the xls trick i'm quite sure is nice, but probably doesn't handle all the "weird" issues there are with this "generate base class" pattern.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 17, 2005 1:09 pm 
Beginner
Beginner

Joined: Fri Nov 04, 2005 3:51 pm
Posts: 32
Quote:
the xls trick i'm quite sure is nice, but probably doesn't handle all the "weird" issues there are with this "generate base class" pattern.


Yeah, definintely. It was just a quick & dirty trick at the time and wouldn't use it as a catch-all for everyone's mapping (since, as you said, as-is, wouldn't handle all cases). Extending hbm2java would be the better way if you have more time to do it right.


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.