I'm using the eclipse plugin to generate my hbm.xml files from my database schema and am wondering how I can customize the names being generated for my <set> and <many-to-one> mappings.
I've got the following generated hbm.xml file :
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Aug 22, 2006 11:05:10 AM by Hibernate Tools 3.2.0.beta6a -->
<hibernate-mapping>
<meta attribute="use-in-tostring">true</meta>
<meta attribute="use-in-equals">true</meta>
<meta attribute="generated-class">com.soso.model.OffenderBase</meta>
<meta attribute="scope-class">public abstract</meta>
<class name="com.soso.model.Offender" table="OFFENDER">
<id name="id" type="java.lang.Long">
<column name="ID" precision="22" scale="0" />
<generator class="sequence">
<param name="sequence">offender_id_seq</param>
</generator>
</id>
<many-to-one name="nameSuffixRef" class="com.soso.model.NameSuffix" fetch="select">
<column name="SUFFIX_ID" precision="22" scale="0" />
</many-to-one>
<set name="victimses" inverse="true">
<key>
<column name="OFFENDER_ID" precision="22" scale="0" not-null="true" />
</key>
<one-to-many class="com.soso.model.Victim" />
</set>
</class>
</hibernate-mapping>
The problem is that for my many-to-one name I want it to be nameSuffix, which is the name of the class, not nameSuffixRef (which is based on the table name name_suffix_ref).
Also, in the set name, I want the name to be victims, not victimses. This is also being generated based on the table name (VICTIMS) not the object / class name which is 'victim'.
I've looked through the documentation and haven't found a good reference on how to modify the template files that generate these hbm.xml files (i.e set.hbm.ftl, persistentclass.hbm.ftl, etc)
I'm running into this problem with alot of my generated hbm.xml files. Part of the problem is that I don't have the ability to change the actual table names in the database, and thus am left with modifying the names of the tables in my hibernate.reveng.xml file like :
Code:
<table class="us.co.douglas.soso.model.Victim" name="VICTIMS">
....
</table>
Is there some way for me to modify the template files (say for instance set.hbm.ftl) and make it use the object name for these references, instead of the table name? I'd prefer not to have to go and modify all of my hbm.xml files by hand if I can avoid it.
Any help / suggestions would be greatly appreciated.