Trying to manage some collection on an entity, I found that my setter don't set correctly the collection. I ask on some forums without finding why this behavior happen.
[Stack overflow post|https://stackoverflow.com/questions/54761884/calling-clear-on-a-jpa-entity-property-using-accesstype-property-fails/54769007?noredirect=1#comment96537854_54769007]
[Hibernate post|https://discourse.hibernate.org/t/accesstype-property-and-setter-problem-on-map/2320/3]
I made several tests and I'm here: - the setter in my example must set the collection and when the persist method is call it recreate the entity and then call the setter. But some strange things happen and during its execution the argument map is emptied (juste after the call to clear) - Some people gave me advices about the good practices for manipulate collections, but I think this case is not concerned with this.
I create a test case that reproduce the issue: https://github.com/Mohicane/jpa-accesstype/tree/master/accesstype.property.testcase
h3. EDIT: I finally find what happen (I hope): when the setter is call, the map argument *is the same instance* as the map entity. So when the clear is done, the map is empty. CQFD But this is a problem. I'm not an Hibernate expert, but I see here either an efficiency problem (why set the map with the same instance. the map is allready uptodate), or a real problem (if it's important to execute the set, then it must be an independant collection no?) |
|