Setter improper behavior on entity with AccessType.PROPERTY

Description

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

Hibernate post

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

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?)

Environment

Discover using:

  • spring-boot 2.1.3

  • java 1.8.0_152

  • mysql 8.0.12

  • Windows 10 Professional 64bits

Status

Assignee

Gail Badner

Reporter

Gabriel Macerot

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

5.0.12
5.3.7

Priority

Critical