-->
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: Load children when FK is not the parent PK
PostPosted: Wed Dec 12, 2007 6:20 am 
Newbie

Joined: Sun Nov 18, 2007 3:22 am
Posts: 8
Hi,
I run into a problem when trying to load an parent object and its children.
My parent class Has a assigned PK and an Identity column.

I have a unique constaint on the Identity.

The children has the Identity column of the father as FK.
The load did not bring the children.
When i changed the PK of the Parent to the Identity it brought all the children but i cant change my schema.
I am attaching the code:

DB schema:
CREATE TABLE [dbo].[XXXParent](
[mPIdentity] [int] IDENTITY(1,1) NOT NULL,[PID] [int] NOT NULL,
CONSTRAINT [PK_XXXParent] PRIMARY KEY CLUSTERED
([PID] ASC)) ON [PRIMARY]

CREATE TABLE [dbo].[XXXChild](
[mPIdentity] [int] NOT NULL,[CID] [int] NOT NULL,
CONSTRAINT [PK_XXXChild] PRIMARY KEY CLUSTERED
([mPIdentity] ASC,[CID] ASC)) ON [PRIMARY]
ALTER TABLE [dbo].[XXXChild] WITH CHECK ADD CONSTRAINT [FK_XXXChild_XXXParent] FOREIGN KEY([mPIdentity])
REFERENCES [dbo].[XXXParent] ([mPIdentity])
ALTER TABLE [dbo].[XXXChild] CHECK CONSTRAINT [FK_XXXChild_XXXParent]

Mapping(parent):
<class name="Root" table="XXXParent">
<id name="PID">
<generator class="assigned" />
</id>
<property name="PIdentity" column="mPIdentity" update="false" insert="false"/>
<bag name="Leafs" cascade="all" optimistic-lock="false" inverse="true" lazy="false" table="XXXChild">
<key>
<column name="mPIdentity"/>
</key>
<one-to-many class="Leaf"/>
</bag>
</class>
Mapping(child):

Thx,
Tomer


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.