Hibernate Tools : how to generate base classes?
I recently installed Eclipse Helios and Hibernate Tools 3.4.0.Beta1.
I've been trying to generate "base class" from mapping files but can't find out how to do. Let us say I have a mapping file called Individual.hbm.xml. I want Hibernate Tools to generate 2 POJOs : - a BaseIndividual.java that would contain constructors and getters/setters - an Individual.java where I could add "custom" code tha开发者_如何学Pythont would not be removed whenever I re-generate POJOs
I spent a lot of time seeking information but never found a practical answer. If anyone can help... thanks in advance
I have just come across your question while trying to do the same thing myself (I think).
What I have done is set the following in my hbm.xml config file:
<class
name="User"
table="USERS">
<meta attribute="generated-class">ocs.authentication.UserBase</meta>
<id
name="user_id"
column="USER_ID"
type="integer">
<generator class="increment"/>
</id>
<property
name="username"
column="USERNAME"
type="string" />
</class>
Note the <meta attribute="generated-class">
section. This will cause the generated class to be called UserBase (in this case).
You can then create another class (called User for example) that will extend this base class:
public class User extends UserBase {
public User() {
}
public void SomeFunction() {
...
}
}
This seems to be working for me. I hope this is useful for you, or for others wanting to do a similar thing.
I'm looking for a way to do it as well. What I'm doing right now, is to:
- to save my custom class "Individual.java" to another package without updating the reference.
- generate all my pojo (with the name of the table, ie Individual)
- rename them tablename+"Base" (ie IndividualBase) without updating the references)
- then moving my custom class (Individual) which extends the pojo from the other package.
Did you find out an automatic way to do it by for example:
- Using a custom template
- Writing you own ant task
- Configure hibernate.reveng.xml
I agree that Hibernate Synchronizer was doing it quite well!
精彩评论