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.  [ 3 posts ] 
Author Message
 Post subject: Need help with customizing generated hbm.xml files
PostPosted: Tue Aug 22, 2006 1:24 pm 
Newbie

Joined: Fri Oct 17, 2003 11:31 am
Posts: 19
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.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 22, 2006 7:45 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Have you looked to the docs?
See http://www.hibernate.org/hib_docs/tools/reference/en/html/reverseengineering.html#custom-reveng-strategy
and
http://www.hibernate.org/hib_docs/tools/reference/en/html/ant.html#hbmtemplate

for some answers.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 24, 2006 3:30 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
david's suggestion is what i would also suggest ;)

look for many-to-one to control it explicit via reveng.xml

if you have a better algorithm to it more generally a custom reveng strategy is recommended.

_________________
Max
Don't forget to rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.