-->
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.  [ 3 posts ] 
Author Message
 Post subject: one to one annotations
PostPosted: Tue Dec 22, 2009 12:40 pm 
Newbie

Joined: Tue Dec 22, 2009 12:35 pm
Posts: 2
That is good post..well i am having a problem and it is driving me nuts.
i have a scenario in which each product it link to some other product.
table = product
id (primary key),
link(pointing to id)

this link can and cannot be null.its kind of parent child relation in one table..after searching and found nothing i thought may b my design is bad so i split the product table
table = product
id

table = pr_link
prod_id ()
link_id ()

both are foreign keys from product table.
is it one to one relation and iam unable to fix it..please help thank you..


Top
 Profile  
 
 Post subject: Re: one to one annotations
PostPosted: Tue Dec 22, 2009 1:00 pm 
Beginner
Beginner

Joined: Tue Nov 03, 2009 9:38 am
Posts: 24
What's the problem with the first design?

Don't use NOT NULL constraints on the 'link' column in your database and don't place nullable = false on the @OneToOne annotation.
The link reference in your article object maybe null, so this shouldn't be a problem.

The second approach would have to be used for a one-to-many relation but might work for a one-to-one relation as well. You just need a @JoinTable on your relation.


Top
 Profile  
 
 Post subject: Re: one to one annotations
PostPosted: Mon Dec 28, 2009 11:25 am 
Newbie

Joined: Tue Dec 22, 2009 12:35 pm
Posts: 2
hi..
let me finish it..sorry for late reply
i have product table in which i have both new and second hand products , new product may have and may not have second hand product.i call second hand product as link . the problem was that second hand product (link) again refer to product table..it is like parent child in one table...

now product table look like this

product
pid
link

.
i have fixed it by doing following mapping...
@OneToOne
@JoinColumn(name="link")
private ProductImpl productLink;


thanks.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.