Hi, I'm new to annotations & using Hibernate outside of Spring. I'm not sure what my configuration needs to be in order to do this (or if you can)
I'm retrieveing a child entity directly from Hibernate with a query including it's parent entity with cross-references. The child entity is the only object in a collection which could have another (1000?) rows in the db with same foreign key value.
I process some logic to create 2 or more instances of the child class and distribute some numeric values between them. The I want the original row deleted and the new entities persisted.
it seems that as soon as I hit the first add, that the entire collection is fetched. Is there a way to supress this and still have it work correctly? There is an obvious overhead in create 1000+ objects that are not needed.
your collection is mapped inverse so both ends "know" of the collection. There should be no problem if you save (or delete) your children without touching the parent - as long as you have a reference to the parent in your child instance. You should also be able to see this from your DB schema. I'd expect that your child table has a FK column referencing the parent table whereas the parent table does not show any sign of "knowledge" about the child table.
On your original issue with the collection fetching. This might be dependent on the kind of collection you choose. I could imagine a HashSet has to be loaded completely in order to decide if the child is actually to be added or not. For each existing entry the hashCode must be calculated to check if the new item is actually a duplicate (will not add) or not (will add).
posted 10 years ago
Thanks, I kinda figured that when I thought about it a while. Went ahead and did just that.
It's exactly the same and completely different as this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop