-->
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.  [ 9 posts ] 
Author Message
 Post subject: Persisting Subclasses without State
PostPosted: Tue Sep 28, 2004 11:08 pm 
Newbie

Joined: Tue Sep 28, 2004 2:01 pm
Posts: 17
We are automating generation of our persistence classes against an existing database schema. The results are value objects. We put our business logic in extensions of the generated classes. The extensions have no persisted state themselves and no associated table. However, those are the objects we instantiate. How do we persist the extensions?

Leaning toward velocity script to generate one class that merges the hard-carved extensions with the automatically generated value objects. Hoping there is a simpler strategy.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 29, 2004 12:04 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
why not have hbm2java make you an abstract class with the value properites and then let you extend it to implement the biz-methods ?

Then you can easily regenerate again and again as the hbm2java will only override the abstract class ?

Add a <meta attribute="generated-class">AbstractXXX</meta> to the class mapping and you will get it.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 29, 2004 12:05 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
...and hbm2java handles all the messy stuff about handling the correct generation of associations and proper inheritance etc. when you have subclasses ....

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 29, 2004 4:26 am 
Newbie

Joined: Tue Sep 28, 2004 2:01 pm
Posts: 17
[quote="max"]why not have hbm2java make you an abstract class with the value properites and then let you extend it to implement the biz-methods? quote]

Sounds like a great idea. This allows you to decide at runtime what type to instantiate provided it extends the abstract class specified in the ORM file. Many important applications for this in terms of customizing runtime behavior.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 29, 2004 9:11 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
treespace wrote:
max wrote:
why not have hbm2java make you an abstract class with the value properites and then let you extend it to implement the biz-methods?
Quote:

Sounds like a great idea. This allows you to decide at runtime what type to instantiate provided it extends the abstract class specified in the ORM file. Many important applications for this in terms of customizing runtime behavior.


I don't think you are following me (or i ain't following you ;)

The hbm2java feature allows it to generate a AbstractXXX where you mention XXX in the mapping file.

Thus you only basically write "class XXX extends AbstractXXX { ... }" and when the hbm2java is rerun it will only redo AbstractXXX.

The mapping file will still map to the concrete class.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 29, 2004 10:21 am 
Newbie

Joined: Tue Sep 28, 2004 2:01 pm
Posts: 17
I follow you now. The meta tag overrules the name of the generated class without messing with the mapping at all. There is no "abstract" in a literal sense. This is precisely what I was looking for.

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 29, 2004 3:00 pm 
Newbie

Joined: Tue Sep 28, 2004 2:01 pm
Posts: 17
There is no input box for the "generated-class" meta tag in the middlegen GUI. I should be able to doctor the velocity script to include that meta tag at the top of each class.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 29, 2004 3:17 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
yes - should be trivial (even though not as nice as it would create an abstract class for all your classes even though you might need it for all).

Oh well ,*)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 29, 2004 3:38 pm 
Newbie

Joined: Tue Sep 28, 2004 2:01 pm
Posts: 17
I should probably download the plug-in source to see where you specify your own velocity script but perhaps you know off the top of your head. Meanwhile I am unzipping the plug-in jar, updating hibernate.vm, then zipping it back up again. A little clunky but at least I get automatic meta tags for generated-class.


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