Hibernate cannot initialize parent's field without getters (Many-to-One relationship)

Description

Hibernate does not initialize Many-to-One relationship if parent's field are not accessed by getters.

Let's assume the Database has these info:

Person
id | name
1 | foo parent

Child
id | name
1 | foo

Below code should be self-explanatory (comments show lines printed on console). There is also a HibernateUtil class that creates SessionFactory which is omitted for brevity.

Does this not render Field Access almost useless (other than not needing to annotate @Transient on methods)? Getters setters everywhere just generate noise, especially for projects that cannot use Project Lombok (we are using Play Framework). Also, this is in total contradiction with the documentation (links below). I find it really surprising no one has raised this issue, which makes me really doubtful if this is a bug or wrong configuration on my part, do correct me if I am wrong.

https://docs.jboss.org/hibernate/orm/5.4/userguide/html_single/Hibernate_User_Guide.html#entity-pojo-accessors
"Although Hibernate does not require it, it is recommended to follow the JavaBean conventions and define getters and setters for entity persistent attributes. Nevertheless, you can still tell Hibernate to directly access the entity fields."

https://docs.jboss.org/hibernate/orm/5.4/userguide/html_single/Hibernate_User_Guide.html#field-based-access

App.java

Person.java

Child.java

Environment

Hibernate 5.4.9.Final / Hibernate 5.3.14.Final / Hibernate 5.2.18.Final

openjdk version "1.8.0_232"
OpenJDK Runtime Environment (Zulu 8.42.0.21-CA-macosx) (build 1.8.0_232-b18)
OpenJDK 64-Bit Server VM (Zulu 8.42.0.21-CA-macosx) (build 25.232-b18, mixed mode)

MySQL 5.7.19

mysql-connector-java 5.1.48 / mysql-connector-java 8.0.18

Assignee

Unassigned

Reporter

Fu Hong Yi

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure