Hello,
I'm working with EMF models persisted using Elver/Teneo and Hibernate 3.1.3.
My core problem is: Given a Parent entity with a lazily fetched one-to-many "children" association to some Child object:
Say I map the children as a list. Say one Parent has 1000 children. If I do Parent.getChildren().add(newChild) and persist. Then Parent.getChildren() will retrieve all 1000 children FIRST, and then persist the newChild. Even if I map the children association as extra-lazy, this behavior doesnt change. I tried to be clever, created a dummy child in the 1000 children, then did "From Parent p left join fetch p.children c where c.name="dummy"". This made Parent.getChildren() get initialized as a 1 member list even though there were 1000 in DB. Added the newChild. Saved, which went fine too. However newChild ended up having a list index of 2, same as a previously existing child. Next time when I retrieved the list, there were still 1000 objects, even though there were 1001 in DB, because the newer number 2 overwrote the old number 2 in memory. Ok, so I understand, all this is happening because I said I wanted a list.
Tried to switch from a list to a set, but I'm using EMF models with Elver/Teneo mapping the models to Hibernate. The EMF models themselves only use (E)Lists in Java, and Hibernate wasnt happy trying to persist/retrieve an ArrayList to/from a set mapping, perhaps understandably so.
Tried to switch over to a Bag. But apparently Bags have horrendous update/delete performance due to the fact that object instances cant be uniquely correlated to DB rows.
Tried to switch over to idbag to get over a bag's unique-identification-of-objects problem. But the idbag mapping doesnt allow
one-to-many associations at all
Can someone please suggest to me a solution? How can I save a new child to a one-to-many association without retrieving all the current children? Also, why arent one-to-many associations allowed with an idbag?
O Gods of Hibernate, I beseech you, please respond.
Thanks,
Sundeep