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...
|