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:
id | name
1 | foo parent
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.
"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."
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 22.214.171.124-CA-macosx) (build 1.8.0_232-b18)
OpenJDK 64-Bit Server VM (Zulu 126.96.36.199-CA-macosx) (build 25.232-b18, mixed mode)
mysql-connector-java 5.1.48 / mysql-connector-java 8.0.18