-->
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.  [ 6 posts ] 
Author Message
 Post subject: how to specify the foreing key names on reverse engineering
PostPosted: Thu Feb 23, 2006 7:53 pm 
Beginner
Beginner

Joined: Mon Nov 28, 2005 11:03 am
Posts: 39
Location: Madrid
Dear members,

I have a relation like this:
Code:
Shareholder         ShareholderType
type              --> shareholder_type_id

so type is a foreign key of shareholder_type_id. I would like to get on the generated class the attribute name of type to be mapped into type instead of default generation setting which is: shareholderType.
on the Shareholder.hbm.xml file I get (using hbm2hbmxml)

Code:
    <many-to-one name="shareholderType" class="com.schinvest.lra.domain.ShareholderType" fetch="select">
            <column name="type" not-null="true" />
        </many-to-one>


but I would like to get instead shareholderType name the simple name type.

Looking into the Hibernate Tool documentation, you can redefine some properties on the reverse enginerring process, but for me it is confuse, because there is information about the foreign key setting on multiple places, for example, on column node:

Code:
<column
name="column_name"
jdbc-type="java.sql.Types type"
type="hibernate_type"
property="propertyName"
exclude="true|false"
foreign-catalog="catalogName"
foreign-schema="schemaName"
foreign-table="tableName"
foreign-column="columnName"
/>


and also there is a node <foreign-key> inside the node table with the following information:

Code:
<foreign-key
  name="foreignKeyName"
  foreign-catalog="catalogName"
  foreign-schema="schemaName"
  foreign-table="tableName"
>
<column-ref local-column="columnName" foreign-column="foreignColumnName"/>
</foreign-key>


where do I have to change the information in order to really get type on the Shareholder class?

(Note: The root table definition should be something like this:
Code:
<table
catalog="catalog_name"
schema="schema_name"
name="table_name"
class="ClassName"
>
<primary-key...>
<column...>
<foreign-key...>
</table>

)

The table definition is:

Quote:
CREATE TABLE shareholder_type (
shareholder_type_id INT(2) UNSIGNED NOT NULL AUTO_INCREMENT
, name VARCHAR(10) NOT NULL
, PRIMARY KEY (shareholder_type_id)
)TYPE=InnoDB;

CREATE TABLE shareholder (
shareholder_id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT
, type INT(2) UNSIGNED NOT NULL
, CONSTRAINT fk_shareholder_2 FOREIGN KEY (type)
REFERENCES shareholder_type (shareholder_type_id)
)TYPE=InnoDB;
ALTER TABLE shareholder COMMENT='Share holders information'


I have tried with some change combinations but I didn't get the expected result.

Thanks in advance,

David Leal

_________________
David Leal


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 24, 2006 7:51 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
it is not possible yet via reveng.xml (when it will be possible it will most likely be in the <foreign-key> region but haven't made a decision yet).

anyway, it is controllable via code by implementing reverseengineeringstrategy that returns what you want for the methods foreignKeyToEntityName and foreignKeyToCollectionName.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 24, 2006 9:52 am 
Beginner
Beginner

Joined: Mon Nov 28, 2005 11:03 am
Posts: 39
Location: Madrid
Max,

Thanks again, I am any way surpise about your comment because on the User Manual Documentation (it is true that it is a bet version) it seems to be possible to configure it with some of these keys.

It is no so much important for me, I will wait until you make a desition about how to setup vía reveng.xml.

Thanks again,

David

_________________
David Leal


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 24, 2006 10:07 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
where in the docs does it state this ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 24, 2006 11:05 am 
Beginner
Beginner

Joined: Mon Nov 28, 2005 11:03 am
Posts: 39
Location: Madrid
look here Max:

http://www.hibernate.org/hib_docs/tools ... e/#d0e1122

_________________
David Leal


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 24, 2006 12:08 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
ok...i can see the ambigious point here ;)

The property column is only used for properties not collections nor many-to-one...but i guess it could make sense to use it for the many-to-one part.

_________________
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.  [ 6 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.