-->
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: Objects with composite keys not updated
PostPosted: Wed Dec 22, 2004 11:45 am 
Newbie

Joined: Wed Dec 22, 2004 11:22 am
Posts: 1
We have a problem with composite keys and hibernate.

Below i have attached the database design and parts from the hibernate mapping files.

When i create a new article i want to set the vendor, so i set the vendor in the article also i add the article to the vendors collection of articles.

But the vendor id is never written into the database.
What i am doing wrong?

Thanks in advance,
Thomas

I have a database design like this (shorten to show only the point):

-- LOCATION TABLE --
Code:
create table location_interface (
   location_id varchar(20) not null,
   city varchar(40),
);
alter table location_interface add constraint location_interface_pk primary key (location_id);

-- VENDOR TABLE --
Code:
create table vendor_interface (
   vendor_id varchar(20) not null,
   location_id varchar(20) not null,
   vendor_name varchar(60),
);
alter table vendor_interface add constraint vendor_interface_pk primary key (vendor_id,location_id);
alter table vendor_interface add constraint vendor_if_location_fk foreign key (location_id) references location_interface (location_id);

-- ARTICLE TABLE --
Code:
create table article_interface (
   article_id varchar(20) not null,
   location_id varchar(20) not null,
   description varchar(80),
   vendor_id varchar(20),
);
alter table article_interface add constraint article_interface_pk primary key (article_id,location_id);
alter table article_interface add constraint article_if_location_fk foreign key (location_id) references location_interface (location_id);
alter table article_interface add constraint article_if_vendor_fk foreign key (vendor_id,location_id) references vendor_interface (vendor_id,location_id);


I hope now you can see the releation of the entities.

Now the parts in the xml files regarding the relations:

-- LOCATION --
Code:
    <id
        name="locationId"
        type="java.lang.String"
        column="LOCATION_ID"
    >
        <generator class="assigned" />
    </id>
    <set
        name="articleInterfaces"
        lazy="true"
        inverse="true"
      cascade="none"
    >
        <key>
            <column name="LOCATION_ID" />
        </key>
        <one-to-many
            class="ArticleInterface"
        />
    </set>
    <set
        name="vendorInterfaces"
        lazy="true"
        inverse="true"
      cascade="none"
    >
        <key>
            <column name="LOCATION_ID" />
        </key>
        <one-to-many
            class="VendorInterface"
        />
    </set>

-- VENDOR --
Code:
    <composite-id name="comp_id" class="VendorInterfacePK">
        <key-property
            name="vendorId"
            column="VENDOR_ID"
            type="java.lang.String"
            length="20"
        />
        <key-property
            name="locationId"
            column="LOCATION_ID"
            type="java.lang.String"
            length="20"
        />
    </composite-id>   
   <many-to-one
        name="locationInterface"
       class="LocationInterface"
       update="false"
       insert="false"
   >
       <column name="LOCATION_ID" />
   </many-to-one>
    <set
        name="articleInterfaces"
        lazy="true"
        inverse="true"
      cascade="none"
    >
        <key>
            <column name="VENDOR_ID" />
            <column name="LOCATION_ID" />
        </key>
        <one-to-many
            class="ArticleInterface"
        />

-- ARTICLE --
Code:
    <composite-id name="comp_id" class="ArticleInterfacePK">
        <key-property
            name="articleId"
            column="ARTICLE_ID"
            type="java.lang.String"
            length="20"
        />
        <key-property
            name="locationId"
            column="LOCATION_ID"
            type="java.lang.String"
            length="20"
        />
    </composite-id>   
    <many-to-one
        name="locationInterface"
       class="LocationInterface"
       update="false"
       insert="false"
   >
       <column name="LOCATION_ID" />
   </many-to-one>
   <many-to-one
        name="vendorInterface"
        class="VendorInterface"
        not-null="true"
      insert="false"
      update="false"
    >
        <column name="VENDOR_ID" />
        <column name="LOCATION_ID" />
    </many-to-one>


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.