Tuesday 15 July 2014

java - Make Hibernate treat detached objects as same instance -


I have many relationships between the two tables, I first fill the parent objects with the child objects and vice versa. When I stumble before a new, unseen hair object, I add it to a hash map and connect with my parents and children with my collection as per the need. Every repetition I check is that the child is already present in the map, and if it is not so, then I add it to the map and make it, and certainly connects the children and parents to their collection. However, in the end, when I keep all the parents, the children are sometimes referred to as preferences, I get duplicates in the hair table. How can I tell Hibernate that these duplicates are the same thing and the same object?

A solution will be to ignore the child before continuing every new person, so I can get his ID and have learned that the same thing is now learned but is it achieved without continuing between the commands That is, in the end, when all the mapping is set, (to guardian objects only) to call?

Instead of the map I used to use, separate collections for parents and child objects Do I. After this I only retained the original item collection and this was the same (because the child's object can not exist without any original object, but parents without child objects, otherwise I can continue the child object instead ).

> The problem with the map was that although you add value to any key keys from the collection values ​​to specific key collection values, it does not refer to the same object, that is, it creates a new one for the other key store That is why in this case you get duplicates while keeping the main values ​​(which are the original objects).


No comments:

Post a Comment