AccessType.PROPERTY and setter problem on Map

That’s make several days I came across a problem I post on Stackoverflow:

I wrote a UnitTest that reproduce this and I think maybe there is an issue here.

I wrote a UnitTest that reproduce this and I think maybe there is an issue here.

Indeed, there is an issue, but not in Hibernate, it’s because you used the Collection Clear Anti-Pattern.

Ok I made some debugging and what a surprize when I discover that during persist method when the setter is called by reflection, the value argument become empty???

Seriously, there’s something I don’t understant. Then I try to wrap my the map arguments in an inner-method map and it’s work???

Working example:

    public void setMyEnumsByProperty(final Map<MyEnum, Integer> myEnums) {
        // if not wrapped, the map become empty after clear is called!!!!
        Map<MyEnum, Integer> temp = new EnumMap<>(myEnums);
        this.myEnumsByProperty.clear();
        for (MyEnum myEnum : temp .keySet()) this.myEnumsByProperty.put(myEnum, temp .get(myEnum));
    }

I’m sorry to insist but there’s something not clear here… And I really think there’s an issue.

And I really think there’s an issue.

In the true spirit of open-source software development, if you think you found an issue, then you have to open a Jira issue.

Don’t forget to add a replicating test case as well, otherwise, the issue will get closed.

More, if this problem is important to you, then you should provide a Pull Request with a fix too.

Looking forward to getting your contribution.

Thank you!
I follow your advice.

[HHH-13289] Setter improper behavior on entity with AccessType.PROPERTY - Hibernate JIRA

I created this JIRA issue. But it’s the first time and I’m not sure I’ve done it correctly.

There’s still nobody on the task, nor answer.

Did I make something wrong?