-->
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.  [ 1 post ] 
Author Message
 Post subject: Hibernate, trouble with composite foreign key
PostPosted: Thu Oct 09, 2008 4:36 am 
Newbie

Joined: Thu Oct 09, 2008 4:01 am
Posts: 1
Location: Moscow
I got two tables:
1) CITIES:
ID VARCHAR2(N)
ACCOUNT_ID BIGINT
NAME VARCHAR2(N)

PRIMARY KEY (ID, ACCOUNT_ID)

2) HOTELS:
ID VARCHAR2(N)
ACCOUNT_ID BIGINT
NAME VARCHAR2(N)
CITY_ID VARCHAR2(N)

PRIMARY KEY (ID, ACCOUNT_ID)
FOREIGN KEY (CITY_ID, ACCOUNT_ID)

I try to map these tables to java beans City and Hotel correspondingly:
1) public class City {
private String id;
private String name;
private Long accountId;
...............
}

2) public class Hotel {
private String id;
private Long accountId;
private String name;
private City city;
...............
}

Mapping document looks so:

<class name="refbeans.City" table="CITIES">
<composite-id>
<key-property name="id" type="string"/>
<key-property name="accountId" type="long" column="ACCOUNT_ID"/>
</composite-id>

<property name="name" type="string"/>
</class>

<class name="refbeans.Hotel" table="HOTELS">
<composite-id>
<key-property name="id" type="string" column="ID"/>
<key-property name="accountId" type="long" column="ACCOUNT_ID"/>
</composite-id>

<property name="name" type="string"/>

<many-to-one name="city" class="refbeans.City">
<column name="CITY_ID"/>
<column name="ACCOUNT_ID"/>
</many-to-one>
</class>

but an error is returned while running:
Repeated column in mapping for entity: refbeans.Hotel column: ACCOUNT_ID (should be mapped with insert="false" update="false")

If I add insert and update with the value "false" to <many-to-one> element it works, but it doesn't fill field cityId in HOTELS table. How I supposed to fill this field?

Thanks in advance


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.