-->
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: Problem generating many-to-one relation using reveng.xml
PostPosted: Fri Jan 16, 2009 2:38 pm 
Newbie

Joined: Thu Jan 15, 2009 3:55 pm
Posts: 12
Hello,
I'm trying to create 2 *.hbm files via reverse engineering.
My problem is, that the the hbm files are generated but without many-to-one relationship.

Code:
Used Env:
Eclipse:  3.4
Oracle: 9i
driver: ojdbc14.jar
hibernate: hibernate3.jar, hibernate-tools.jar


project.reveng.xml:
Code:
<table-filter match-name="ACFT_NOSE" match-schema="ODS_ADMIN1"></table-filter>
   <table-filter match-name="ACFT_TAIL" match-schema="ODS_ADMIN1">
</table-filter>
<table catalog="ODS_ADMIN1" schema="ODS_ADMIN1" name="ACFT_TAIL"
class="com.ual.ods.hibernate.test222.AcftTail">
<primary-key></primary-key>
</table>
<table catalog="ODS_ADMIN1" schema="ODS_ADMIN1" name="ACFT_NOSE"
class="com.ual.ods.hibernate.test222.AcftNose">
<foreign-key foreign-catalog="ODS_ADMIN1" constraint-name="MOTHER"
foreign-table="ACFT_TAIL" foreign-schema="ODS_ADMIN1">
<column-ref local-column="TAIL_NBR" foreign-column="TAIL_NBR" />
<many-to-one property="child"/>
</foreign-key>
</table>


hibernate.cfg.xml:
Code:
<hibernate-configuration>
    <session-factory>
         <property name="hibernate.bytecode.use_reflection_optimizer">false</property>
        <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
        <property name="hibernate.connection.password">pass</property>
        <property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1531:db1</property>
        <property name="hibernate.connection.username">user</property>
        <property name="hibernate.default_schema">ODS_ADMIN1</property>
        <property name="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</property>
        <property name="hibernate.default_catalog">ODS_ADMIN1</property>
    </session-factory>
</hibernate-configuration>


Generated sample hbm:
Code:
<hibernate-mapping>
    <class name="com.ual.ods.hibernate.test222.AcftNose" table="ACFT_NOSE">
        <id name="noseNbr" type="java.lang.String">
            <column name="NOSE_NBR" length="4" />
            <generator class="assigned" />
        </id>
        <property name="tailNbr" type="java.lang.String">
            <column name="TAIL_NBR" length="6" />
        </property>
.
.

</class>
</hibernate-mapping>

----------------------------------------

but I expected:

Code:
<hibernate-mapping>
    <class name="com.ual.ods.hibernate.test222.AcftNose" table="ACFT_NOSE">
        <id name="noseNbr" type="java.lang.String">
            <column name="NOSE_NBR" length="4" />
            <generator class="assigned" />
        </id>


<many-to-one name="acftTail" class="com.ual.ods.hibernate.AcftTail" fetch="select">
<column name="TAIL_NBR" length="6" />
</many-to-one>
.
.

<
</class>
</hibernate-mapping>


Please help me out? I am stuck badly.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 19, 2009 6:00 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
remove schema and catalog from your reveng.xml since you already specified them as being the default. That might help.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 19, 2009 11:04 am 
Newbie

Joined: Thu Jan 15, 2009 3:55 pm
Posts: 12
Hi Max,

You are perfect as always.
I have already done yesterday and guess what - it was exactally you suggested.
Thanks man once again.

-thanks,
Sudip Das


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 19, 2009 9:40 pm 
Newbie

Joined: Thu Jan 15, 2009 3:55 pm
Posts: 12
Hi,

I was trying to map Tabel1[c1, c2, c3, c4] to Table2[cc1, cc2, cc3, cc4] in many-to-one using reveng.xml:

What should be the syntax for multiple columns (I am able to do it using one column):

I have done till:

Quote:
reveng.xml:


Code:
<table name="FA_SEG">
<foreign-key constraint-name="fkProp2" foreign-table="OPS_FLT_LEG">
<column-ref local-column="c1" foreign-column="cc1" />
<many-to-one property="segToOps" />
</foreign-key>
</table>


Can somebody please complete it?
I would expect to write something like that:
Code:
<table name="FA_SEG">
<foreign-key constraint-name="fkProp2" foreign-table="OPS_FLT_LEG">
<column-ref local-column="c1" foreign-column="cc1" />
<column-ref local-column="c2" foreign-column="cc2" />
...
...
<many-to-one property="segToOps" />
</foreign-key>
</table>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 20, 2009 2:28 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
yes - looks correct. what is the problem ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 20, 2009 3:00 am 
Newbie

Joined: Thu Jan 15, 2009 3:55 pm
Posts: 12
Hi Max,

The problem is Table2 is containing 2 more pk and I'm trying to do with only 2 (for right outer join).
So it is giving error,(which is expected):

Code:
org.hibernate.MappingException: Foreign key (FK7B33A2B1A54948B7:Table1[c1,c2])) must have same number of columns as the referenced primary key (Table2[cc1,cc2,cc3,cc4])


I can solve the problem by manual editing in Table2 like:
Code:
<properties name="FKMaps" insert="false" update="false">
<property name ...
..
..
</property>
</properties>


and then in Table1
Code:
<many-to-one name=...... property-ref="FKMaps">
<column ..>
<column ..>

..
</many-to-one>

But I want to do it using reveng.xml.
Is it feasiable at all?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 20, 2009 8:46 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
reveng might not support partial primary key references (since the code generation would fail)

tried using database level constraints instead of reveng.xml ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 20, 2009 11:03 am 
Newbie

Joined: Thu Jan 15, 2009 3:55 pm
Posts: 12
Hi Max,

Unfortunately it can be done in database level - due to some dependency to other tables.

So, there is no other way to implement using reveng.xml the sql like:

Table1 right out join Table2
on Table1.c1 = Table2.cc1
and Table1.c2 = Table2.cc2
-where Table1 [PK(c8,c9)] and Table2 [PK (cc1,cc2,cc3,cc4)]

But I am able able to do it using manual editing the hbm files by defining:
1. <properties> tag in Table2 -- my choice of columns may not be the PK also.
2. And then property-ref in Table1 to map from Table1.columns to Table2.columns.

Is it some other way to do it?

-thanks,
Sudip Das


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 28, 2009 5:48 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
no, the reveng doesn't handle overlapping associations.

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