Add a warning or special handling when entities cannot be proxified

Description

When an entity has public fields, it cannot be correctly "proxified" unless bytecode enhancement is enabled.
When an entity has final getters/setters, those getters/setters cannot be "proxified" either.

If a user doesn't know about this, at some point he will encounter strange issues of uninitialized entities (when accessing a public field or final getter on the proxy) or even data loss (when storing data on the public field or using a final setter on the proxy). That's acceptable, but what's more annoying is that users have a hard time knowing why this happens.

A demonstration of such an issue can be found here: https://github.com/yrodiere/hibernate-test-case-templates/tree/HSEARCH-2541-HHH. The second-but last commit introduces a failing test case, and the last commit fixes the issue by setting up bytecode enhancement.

I am unsure if those limitations are documented, but even if they are, I think such issues should at least trigger warnings in the logs, or even exceptions (if it's not too much of a change). Ideally those would be triggered during bootstrapping.

Note that another approach would be to disable proxying altogether when such a situation arises, but then again that may be too much of a change for a minor release.

Environment

None

Activity

Show:
Andrea Boriero
March 6, 2017, 4:14 PM

I think the problem is accessing the field directly, even with getters/setters the field will be null.

Yoann Rodière
March 6, 2017, 5:16 PM

I think the problem is accessing the field directly, even with getters/setters the field will be null.

Exactly: without bytecode enhancement, field access cannot be proxified.

Now, people could also access protected or private fields directly, but this is either clearly bad practice or advanced use.
Public fields in a data model seem to be a good practice for some people, though... And final methods are definitely a good thing, they just happen not to work well with proxies. So I think those two cases deserve a red flag somewhere.

Assignee

Unassigned

Reporter

Yoann Rodière

Fix versions

None

Labels

None

backPortable

Backport?

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Affects versions

Priority

Minor
Configure