-->
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: Storing a new record into a table with an FK to another tbl
PostPosted: Fri Oct 12, 2007 3:40 am 
Newbie

Joined: Thu Oct 04, 2007 10:32 am
Posts: 6
Hi,
i want to ask about best practices when storing a new record into a table with an FK to another one using DAOs on Hibernate.

If i have table A and table B, table A having an FK to table B, using DAOs when i try a create on the A entity i have to supply a B object which should be the FK.

I have 2 (maybe there are more) options:

1. Either let the DAOs know about eachother...and do something like this:
....handleCreate(aObjectVO){B b = getObjectBDao.getObjectB(objectBId);
create(new A {....., b);}

2. Either let the service have access to 2 DAOs and manipulate the entities's refferences:
getObjectADao.create(new objectAVO{..., getObjectBDao.getObjectB(objectBId)});

From what i read, option 1 is an antipattern, considering i also use spring, and it will kill the dependency injection on the DAOs...

Option 2 is no more beautiful...

Please advice...


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.