Hi.
I am trying to (write a program to) write hibernate mappings for a legacy database, and using hbm2java to generate java classes from these mappings.
Currently one of my hibernate mapping look like this:
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<class name="com.bmd.bs400.file.Customer" table="CustomerL1" lazy="true">
<id name="Customernr" column="AJAENB"
type="com.bmd.bs400.hibernate.CustomernrUserType">
<meta attribute="use-in-equals">true</meta>
<meta attribute="use-in-tostring">true</meta>
<generator class="native" />
</id>
<property name="postnr" column="AJAICD"
type="com.bmd.bs400.hibernate.PostnrUserType">
<meta attribute="use-in-equals">true</meta>
<meta attribute="use-in-tostring">true</meta>
</property>
<property name="momskode" column="AJJANB"
type="com.bmd.bs400.hibernate.MomskodeUserType">
<meta attribute="use-in-equals">true</meta>
<meta attribute="use-in-tostring">true</meta>
</property>
<!-- Includes SidstRettet -->
<component name="sidstRettet"
class="com.bmd.bs400.file.SidstRettet">
<property name="aendretDato" column="AJALDT"
type="com.bmd.bs400.hibernate.AendretDatoUserType" />
<property name="ajourfoeringsstatus" column="AJCDST"
type="com.bmd.bs400.hibernate.AjourfoeringsstatusUserType" />
<property name="aendretKlokken" column="AJAATM"
type="com.bmd.bs400.hibernate.AendretKlokkenUserType" />
<property name="aendretAf" column="AJAAVN"
type="com.bmd.bs400.hibernate.AendretAfUserType" />
</component>
<set name="Subscribers" inverse="true" lazy="true">
<meta attribute="scope-get">private</meta>
<meta attribute="scope-set">private</meta>
<meta attribute="extra-import">
com.bmd.bs400.file.Subscriber
</meta>
<meta attribute="class-code">
public void addSubscriber(Subscriber Subscriber) {
if (Subscriber == null)
throw new IllegalArgumentException("Null Subscriber");
if (Subscriber.getCustomer() != null)
Subscriber.getCustomer().getSubscribers().remove(Subscriber);
Subscriber.setCustomer(this); this.Subscribers.add(Subscriber);
}
</meta>
<key>
<column name="AJAENB" />
</key>
<one-to-many class="com.bmd.bs400.file.Subscriber" />
</set>
</class>
</hibernate-mapping>
From this hbm2java generates two classes Customer.java and SidstRettet.java, but the extra-import and class-code meta tags are completely ignored.
If I move them outside the <set> they are included in BOTH Customer.java and SidstRettet.java.
Thats not very usefull - is there a way to have some java code included in Customer.java without having it repeated in all its components?
Best regards
Claus Nielsen