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: One-to-one and generator
PostPosted: Thu Jun 15, 2006 8:29 am 
Newbie

Joined: Thu Jun 15, 2006 7:47 am
Posts: 3
Hi, All. Please help me to write mapping.
I have Parent and Child objects which are represented such T-SQls

CREATE TABLE ParentObject(
[ID] int identity (1,1) NOT NULL,
[DisplayAs] [varchar](256)
)

CREATE TABLE ChildObject(
[ParentId] int NOT NULL,
[NumberNext] int NOT NULL
)

The relation is 1:1 (Paremt.Id - Child.ParentId). And the Child.ParentId is primary key.
Parent object should not load Child automatically, I suppose I need to use lazy=true here. Also I need 2 INSERTs only (1 for Parent object, 1 for Child object). Any other T-SQL statements (UPDATE for example) are unnecessary.

I have made some variants for solved the problem, but the result still negative.

1. I have made one-to-one relashion and used class="foreign" in the Child's generator tag. It works, but it always loads Parent with Child. I do not need it, because my Parent object is cached and Child object is changed very often.

2. I have tied to use the Child object as a collection Children in the Parent object ("bag" actually). In such case I need to wrie composite-id in the Child object. But I have only Child.ParentId primary key so with is bad solution.

Actually, now the problem is what shold I write in the "id" and in the "generator" tags of Child object. But I am not sure that now I am not in the deep water...

Thank you.

_________________
http://antipod.russia.webmatrixhosting.net/


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 15, 2006 8:47 am 
Senior
Senior

Joined: Sat Mar 25, 2006 9:16 am
Posts: 150
You have a primary key association one-to-one. Read this, which explains exactly what to do:

http://www.hibernate.org/hib_docs/nhibe ... n-onetoone


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 15, 2006 9:09 am 
Newbie

Joined: Thu Jun 15, 2006 7:47 am
Posts: 3
grennis wrote:
You have a primary key association one-to-one. Read this, which explains exactly what to do:

http://www.hibernate.org/hib_docs/nhibe ... n-onetoone


Thank you. I read this documetn several times. Maybe I do not uderstand something (I hope it so), what's why I decided to write my question here. Would you give two mappings?

thx a lot

_________________
http://antipod.russia.webmatrixhosting.net/


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 10, 2006 10:58 am 
Regular
Regular

Joined: Sun Feb 12, 2006 10:18 pm
Posts: 60
Location: Rosario, Argentina
I'm probably too late for this... but still...
I think that your mapping is NOT one to one, but one-to-many and many-to-one, because you have a parent-child (one to many from parent to child, and many to one from child to parent)


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.