Codegeneration with Root Persistent ClassNB: This only works for Hibernate2 In Root Persistent Class is described how an base class for ones persistent class could look like. This is all great, but what if you (like me) want to use the codegenerator ? How do you inform the codegenerator that your class (or all classes) should extend that base class ? Well - Hibernate2's hbm2java is your friend:
<class name="Person">
<meta attribute="extends">Persistent</meta>
...
...
</class>
The above "snippet" hbm2java will parse and generate something like this:
public class Person extends Persistent {
....
}
And know you can just define your properties in your hbm.xml file and hbm2java will do all the boring work for you :)
But what about subclasses in hbm.xml ?They are no problem. hbm2java simply ignores the "extends" meta tag for any <subclass> or <joined-subclass>.
Do I need to specify the <meta> tag for each <class> ?If you are lazy (as me) and do not want to put that <meta> attribute on each and every class in your hbm.xml file you can do one of two things: Insert an <meta> in top of the hbm.xml file as follows:
<hibernate-mapping>
<meta attribute="extends">Persistent</meta>
...
This will then work as the default for that hbm.xml file and it can (of course) be overriden if you wish to for certain classes. Just add a <meta> tag for those classes as described above. The second option is to put the <meta> tag in a config.xml which can then be provided to hbm2java and then the <meta> tag will be used as an default for ALL your hbm.xml files. Happy code generation!
|