-->
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.  [ 2 posts ] 
Author Message
 Post subject: one-to-one bidirectional mapping
PostPosted: Tue Mar 28, 2006 11:47 am 
Newbie

Joined: Tue Mar 28, 2006 11:32 am
Posts: 3
Location: India
Hi,

I am new to hibernate.

I am facing some problem in creating one-to-one relationship bidirectional.

In my scenario, I have 2 tables named Basket_item and Special_Price_Request.

both tables are 1:1 mapped and PK of Basket_Item is FK in Special_Price_Request, that is Basket_Item is Parent table and Special_Price_Request is child table

In existing solution , I can get the SpecialPriceRequestDO by calling custom finder method that is findByBasketItemFid() on SpecialPriceRequestDAO.

Now I have to change it to get SpecialPriceRequestDO by calling getSpecialPriceRequest() on BasketItemDO.

How should I approach to this ?

Please give me pointer in this direction.

Thanks in advance.
Tushar Gorde

_________________
Tushar Gorde
IBM India Pvt Ltd.
Hyderabad - India


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 28, 2006 12:29 pm 
Expert
Expert

Joined: Mon Jan 09, 2006 5:01 pm
Posts: 311
Location: Sacramento, CA
You are setting up a bidirectional relation (actually any relation) you are not dealing with FK/PK precisely, - you are relating by objects - in other words, the Parent.child is defined as class Parent {Child child=null}... So when you load a parent, you can specify via the Lazy attribute whether or not you'd like to also load (initialize) the "child". So this concept works both ways - eg. Child.parent would have a definition of class Child { Parent parent=null}...

I illustrate this with Parent/Child since it is a 1-to-Many - and if you want to make it 1-to-1, then you'll declare the many side "unique". (this mapping of 1-to-M is a special mapping for implementing 1-to-1). Or you can use 1-to-1 on both sides of the mappings. However, the later forces you to use the same PK on each Entity. See reference.pdf for more details.

I recently posted a complete bidirectional 1-to-1 (using 1-to-M method & w/ unique) here:

http://forum.hibernate.org/viewtopic.php?t=956962&highlight=onetoone

_________________
-JT

If you find my replies helpful, please rate by clicking 'Y' on them. I appreciate it.


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