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
|