-->
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: Constructor needs parameter which is contained in object
PostPosted: Thu Mar 05, 2009 8:30 am 
Newbie

Joined: Mon Mar 02, 2009 6:42 am
Posts: 6
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;
    }


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 05, 2009 11:04 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
Thats probably because you also mapped two properties "itemId" and "item".
Try to change your mapping so that the many-to-one assocation is the PK. Actually if you have many-to-one which is unique, its a one-to-one.
Code:
<class name="test.io.database.autogenerated.ImageData" table="IMAGE_DATA">
    <id name="itemId">
        <column name="ITEM_ID" precision="22" scale="0" />
        <generator class="foreign">
            <param name="property">employee</param>
        </generator>
    </id>
    ...
    <one-to-one name="item" class="test.io.database.autogenerated.Item" constrained="true">
            <column name="ITEM_ID" precision="22" scale="0" />
    </one-to-one>
...

_________________
-----------------
Need advanced help? http://www.viada.eu


Last edited by mmerder on Thu Mar 05, 2009 11:10 am, edited 2 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 05, 2009 11:06 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
double post

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 06, 2009 4:27 am 
Newbie

Joined: Mon Mar 02, 2009 6:42 am
Posts: 6
How can I add this with my ReverseEngineeringStrategy?
Code:
        <one-to-one name="item" class="test.io.database.autogenerated.Item" constrained="true">
            <column name="ITEM_ID" precision="22" scale="0" />
        </one-to-one>


And you wrote something about an employee, I think this would be the item.

Code:
    <id name="itemId">
        <column name="ITEM_ID" precision="22" scale="0" />
        <generator class="foreign">
            <param name="property">[b]employee[/b]</param>
        </generator>
    </id>


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.