-->
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.  [ 4 posts ] 
Author Message
 Post subject: composite key many-to-one question???
PostPosted: Wed Oct 04, 2006 10:43 am 
Newbie

Joined: Fri Sep 15, 2006 12:00 am
Posts: 2
create table TAA(
FAID int,
FAID2 int,
FaName varchar(50),
CONSTRAINT PK_AA PRIMARY KEY (FAID,FAID2)
)

create table TBB(
FBID int,
FAID int,
FAID2 int,
FbName varchar(50),
constraint PK_BB primary key (FBID),
CONSTRAINT FK_B_A FOREIGN KEY (FAID,fAId2) REFERENCES TAA(FAID,faId2)
)

I have two tables, use composite key, there is a problem in the table TBB mapping XML
the table TAA is right.

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping package="cn.miw">
<class name="Taa" table="TAA" >
<meta attribute="sync-DAO">false</meta>
<composite-id name="Id" class="TAAPK">
<key-property name="Faid2" column="FAID2" type="integer" />
<key-property name="Faid" column="FAID" type="integer" />
</composite-id>

<property
name="FaName" column="FaName" type="string" not-null="false" length="50" />
</class>
</hibernate-mapping>

there is a problem in the table TBB
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping package="cn.miw">
<class name="TBB" table="TBB" >
<meta attribute="sync-DAO">false</meta>
<id name="Id" type="integer" column="FBID" >
<generator class="sequence"/>
</id>

<property name="FbName" column="FbName" type="string" not-null="false" length="50" />

<many-to-one name="Faid2" column="FAID2" class="Taa" not-null="false" ></many-to-one>
<many-to-one name="Faid" column="FAID" class="Taa" not-null="false" ></many-to-one>

</class>
</hibernate-mapping>

the code in red is wrong.
how can I do mapping the TBB???


Top
 Profile  
 
 Post subject: Re: composite key many-to-one question???
PostPosted: Wed Oct 04, 2006 10:54 am 
Newbie

Joined: Fri Sep 15, 2006 12:00 am
Posts: 2
mrzhouhibernate wrote:
create table TAA(
FAID int,
FAID2 int,
FaName varchar(50),
CONSTRAINT PK_AA PRIMARY KEY (FAID,FAID2)
)

create table TBB(
FBID int,
FAID int,
FAID2 int,
FbName varchar(50),
constraint PK_BB primary key (FBID),
CONSTRAINT FK_B_A FOREIGN KEY (FAID,fAId2) REFERENCES TAA(FAID,faId2)
)

I have two tables, use composite key, there is a problem in the table TBB mapping XML
the table TAA is right.

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping package="cn.miw">
<class name="Taa" table="TAA" >
<meta attribute="sync-DAO">false</meta>
<composite-id name="Id" class="TAAPK">
<key-property name="Faid2" column="FAID2" type="integer" />
<key-property name="Faid" column="FAID" type="integer" />
</composite-id>

<property
name="FaName" column="FaName" type="string" not-null="false" length="50" />
</class>
</hibernate-mapping>

there is a problem in the table TBB
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping package="cn.miw">
<class name="TBB" table="TBB" >
<meta attribute="sync-DAO">false</meta>
<id name="Id" type="integer" column="FBID" >
<generator class="sequence"/>
</id>

<property name="FbName" column="FbName" type="string" not-null="false" length="50" />

<many-to-one name="Faid2" column="FAID2" class="Taa" not-null="false" ></many-to-one>
<many-to-one name="Faid" column="FAID" class="Taa" not-null="false" ></many-to-one>

</class>
</hibernate-mapping>

the code in red is wrong.
how can I do mapping the TBB???


and how can build the set in TAA?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 05, 2006 2:19 am 
Regular
Regular

Joined: Tue May 16, 2006 3:32 am
Posts: 117
Use the following mapping style for composite keys:

Code:
many-to-one:

<many-to-one name="person"  class="Person">
    <column name="firstName"/>
    <column name="initial"/>
    <column name="lastName"/>
</many-to-one>



Set:

<set name="persons" inverse="true">
    <key>
         <column name="firstName"/>
         <column name="initial"/>
         <column name="lastName"/>
    </key>

    <one-to-many class="Person"/>
</set>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 17, 2006 5:30 am 
Newbie

Joined: Fri Jul 07, 2006 3:39 am
Posts: 4
I have try this but dont work.

Error is "must have same number of columns as the referenced primary key".

I use your example for my project.

Can you help me?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.