-->
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.  [ 9 posts ] 
Author Message
 Post subject: Problematic two foreign keys
PostPosted: Mon Nov 07, 2005 11:15 am 
Regular
Regular

Joined: Fri Mar 04, 2005 1:33 pm
Posts: 65
Location: U.K.
Hi All,

Hibernate version:
3.0

I am using following Ant script to generate POJOs from given set of hbm.xml files with hibernate-tools.jar:
----------------
<target name="generateCode" depends="generateConf">

<hibernatetool destdir="${gen.dir}">
<configuration>
<fileset dir="${gen.hibernate.mapping.dir}">
<include name="**/*.hbm.xml" />
</fileset>
</configuration>
<hbm2java templatespath="${hibernate.cfg.dir}" destdir="${gen.src.dir}" />

</hibernatetool>
</target>
-----------------

I have a Table EMPLOYEE with two columns which are foreign keys to table ADDRESS. The column names are HOME_ADDRESS and OFFICE_ADDRESS. When hbm2java code runs, it creates two column names like ADDRESS and ADDRESS_1. Is there any way so I get actual foreign key column names in generated POJO instead of ADDRESS and ADDRESS_1 ?

Has any one experienced this before ?

Thanks
Ron


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 07, 2005 4:29 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
dont use the alpha version, use the beta. The beta version does not generate _1 names anymore.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Problem still exists ... multiple foreign key columns ...
PostPosted: Mon Nov 07, 2005 6:10 pm 
Regular
Regular

Joined: Fri Mar 04, 2005 1:33 pm
Posts: 65
Location: U.K.
Hi Max,

The problem still exists ...

I downloaded hibernate-tools.jar 3.1.0-beta1. The hbm.xml still has address and address_1 attributes defined.

My Ant script looks like:

<target name="generateConf" depends="genHibConfig" >
<mkdir dir="${gen.src.dir}" />

<hibernatetool destdir="${gen.dir}">
<jdbcconfiguration
packagename="blah.blah.blah.blah.business.domain"
configurationfile="${gen.hibernate.cfg.dir}/hibernate.cfg.xml"
revengfile="${hibernate.cfg.dir}/hibernate.reveng.xml"/>
<hbm2hbmxml templatepath="${hibernate.cfg.dir}" destdir="${gen.hibernate.mapping.dir}"/>
</hibernatetool>
</target>



<target name="generateCode" depends="generateConf">

<hibernatetool destdir="${gen.dir}">
<configuration>
<fileset dir="${gen.hibernate.mapping.dir}">
<include name="**/*.hbm.xml" />
</fileset>
</configuration>
<hbm2java templatepath="${hibernate.cfg.dir}" destdir="${gen.src.dir}" />

</hibernatetool>
</target>

Please guide.

Thanks
Ron


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 07, 2005 6:22 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
hmm - try with a version from the recent nightly builds and let me know if it continues.... _1 should *not* be generated by beta1.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: multiple foreign keys
PostPosted: Tue Nov 08, 2005 9:17 pm 
Regular
Regular

Joined: Fri Mar 04, 2005 1:33 pm
Posts: 65
Location: U.K.
Hi Max,

I prefer to wait until next version of Hibernate-tools.jar comes out than taking it from nightly build. Any idea when it will be out ?

Thanks
Ron


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2005 4:23 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
as soon as it is ready.

Testing the nightly builds for scenarios like this is the best way to get ensurance that we actually have fixed some user specific bugs (we like that and then have more incitement to do a quicker release ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2005 6:18 am 
Newbie

Joined: Mon Oct 31, 2005 12:01 pm
Posts: 12
you can also write your own RevengStrategy and
overwrite method foreignKeyToEntityName

for example :

Code:
   public String foreignKeyToEntityName(String fk, TableIdentifier childTable, List arg2, TableIdentifier parentTable, List arg4, boolean arg5) {
      if (mappingProps.containsKey(childTable.getName()+"."+fk)) {
         return (String)mappingProps.getProperty(childTable.getName()+"."+fk);
      } else {
         StringBuffer name = new StringBuffer(tableToSimpleClassName(parentTable));      
         name.setCharAt(0, Character.toLowerCase(name.charAt(0)));      
         return name.toString();
      }      
   }



you must also define a mapping(or hard code it). it can look like this in a property file

EMPLOYEE.FK_ADDRESS1=homeAddress
EMPLOYEE.FK_ADDRESS2=officeAddress


Top
 Profile  
 
 Post subject: Multiple foreign keys
PostPosted: Wed Nov 09, 2005 10:27 am 
Regular
Regular

Joined: Fri Mar 04, 2005 1:33 pm
Posts: 65
Location: U.K.
Can you please elaborate what all I need to do to put Reverse Engineering strategy ?

Thanks
Ron


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2005 11:23 am 
Newbie

Joined: Mon Oct 31, 2005 12:01 pm
Posts: 12
1. create your own RevengStrategy-class that extends DelegatingReverseEngineeringStrategy

Code:
public class MyRevengStrategy extends DelegatingReverseEngineeringStrategy {
...


2. set attribute reversestrategy in your <jdbcconfiguration> in ant

Code:
reversestrategy="MyRevengStrategy"



for more information see
http://forum.hibernate.org/viewtopic.php?t=949380
and
http://www.hibernate.org/hib_docs/tools/ant/index.html


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