Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

HHH-19599 : Test demonstrating that a collection accessed via a getter and using Collections#unmodifiableSet is not persisted.#10497

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
boutss wants to merge2 commits intohibernate:main
base:main
Choose a base branch
Loading
fromboutss:HHH-19599

Conversation

boutss
Copy link
Contributor

@boutssboutss commentedJul 9, 2025
edited by hibernate-github-botbot
Loading

HHH-19599 : Test demonstrating that a collection accessed via a getter and using Collections#unmodifiableSet is not persisted.


By submitting this pull request, I confirm that my contribution is made under the terms of theApache 2.0 license
and can be relicensed under the terms of theLGPL v2.1 license in the future at the maintainers' discretion.
For more information on licensing, please checkhere.


https://hibernate.atlassian.net/browse/HHH-19589
https://hibernate.atlassian.net/browse/HHH-19599

Vincent Bouthinon added2 commitsJuly 8, 2025 10:52
Comment on lines +72 to +76
@OneToMany
@Access(AccessType.PROPERTY)
public Set<Command> getCommands() {
return Collections.unmodifiableSet( commands );
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This really isn't a good thing to do. This means that every time Hibernate accesses the collection, it sees a new object. You have two choices:

  1. Use field access instead of property access (I have no clue why you're using@Access(AccessType.PROPERTY) here to begin with, or
  2. CallCollections.unmodifiableSet() in the setter or where you initialize the field.

Otherwise I would say that this is something that's just not supported.

boutss reacted with thumbs up emoji
Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I simplified things for the test, but in reality, we have a class hierarchy where the behavior differs for a given attribute depending on the subclass.
We use property access to configure things differently.

Ideally, we would need to refactor the class model to avoid using property access.

Thank you!

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

And as for option 2, it’s not feasible because we still want the collection to be modifiable internally within the class, but not externally.

But this approach has its limits — and this case proves it.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@gavinkinggavinkinggavinking left review comments

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@boutss@gavinking

[8]ページ先頭

©2009-2025 Movatter.jp