Hibernate version:
3.1 (3.1 beta6 annotations)
I have a typical one-to-many relationship between parent and child. In our case, however, the parent has a lot of these one-to-many and I don't want to put the mapping for all of them in the parent class (don't want to have to load the entire database). Plus, in the UI, most of the child objects are edited/manipulated "on their own". Additionally, the child object could be re-used across many parent objects. For example, the parent is a Customer and the child is a Note. There could not only be Customer notes, but potentially Location notes, Employee notes, ....
I'm wondering what the best practice is for mapping these. I know the documenation indicates a @JoinTable, but I'm not sure how to do this if I don't put any mapping in the parent.
Parent
ID (pk)
Child
ID (pk)
Join
PARENT_FK
CHILD_FK
Alternatively, I could put the foreign key in the child (I know, not recommended). However, I don't really want to load the parent when loading the child. Is there a way (with annotations) to enforce referential integrity without having to load the parent?
Child
ID (pk)
PARENT_FK (fk)
My UI services would call typical crud on the parent and child separately, and since I don't necessary want to load all of the children with the parent, I would also call services such as:
Parent parent = getParent(parentId);
Child child = getChild(childId);
List children = getChildrenByParentId(parentId);
Hopefully this makes some sense. How do y'all solve this?
Thanks.
|