Hibernate version:
Hibernate 3
Name and version of the database you are using:
Oracle 10g
Problem:
Hi,
I have two tables:
Item:
Code:
CREATE TABLE "Test"."ITEM" (
"ID" NUMBER NOT NULL,
"RECONSTRUCTION_ID" NUMBER,
"TYPE" VARCHAR2(45),
CONSTRAINT "PK_ITEM" PRIMARY KEY("ID")
CONSTRAINT "FK_RID" FOREIGN KEY("RECONSTRUCTION_ID")
REFERENCES "Test"."RECONSTRUCTION"("ID")
)
To increment the id a sequence is used
ImageData:
Code:
CREATE TABLE "Test"."IMAGE_DATA" (
"ITEM_ID" NUMBER NOT NULL,
"IMAGE_ID" NUMBER,
"ATTRIBUTE" VARCHAR2(100 byte),
CONSTRAINT "PK_IMGDAT" PRIMARY KEY("ITEM_ID")
CONSTRAINT "FK_ITEM" FOREIGN KEY("ITEM_ID")
REFERENCES "Test"."ITEM"("ID")
CONSTRAINT "FK_IMG" FOREIGN KEY("IMAGE_ID")
REFERENCES "Test"."IMAGE"("ID")
)
Hibernate creates the following constructor:
Code:
/** minimal constructor */
public ImageData(int itemId, Item item) {
this.itemId = itemId;
this.item = item;
}
out of the following mapping file:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 05.03.2009 11:49:30 by Hibernate Tools 3.2.0.beta8 -->
<hibernate-mapping>
<class name="test.io.database.autogenerated.ImageData" table="IMAGE_DATA">
<id name="itemId" type="int">
<column name="ITEM_ID" precision="22" scale="0" />
<generator class="assigned" />
</id>
<many-to-one name="item" class="test.io.database.autogenerated.Item" update="false" insert="false" fetch="select">
<column name="ITEM_ID" precision="22" scale="0" not-null="true" unique="true" />
</many-to-one>
<many-to-one name="image" class="test.io.database.autogenerated.Image" fetch="select">
<column name="IMAGE_ID" precision="22" scale="0" />
</many-to-one>
<property name="attribute" type="string">
<column name="ATTRIBUTE" length="100" />
</property>
</class>
</hibernate-mapping>
How can I tell Hibernate, that itemId is already contained in Item? I expect the following constructor:
Code:
/** minimal constructor */
public ImageData(Item item) {
this.item = item;
}