We're upgrading from Hibernate 4.3.11 to Hibernate 5.2.7 and are getting a NullPointerException in ModelBinder when it tries to access a PrimaryKey. It's null.
We have a mix of HBM and Annotation entities. It happens when an entity is mapped via XML and references an entity that is mapped via annotations - many to one. We're using the legacy bootstrapping process via spring's LocalSessionFactoryBuilder (version 5). I've tried changing to non-legacy native bootstrapping, but that made no difference.
Here's the exception:
NPE in ModelBinder
Originally posted here: https://forum.hibernate.org/viewtopic.php?f=1&t=1044033
I worked around it in the short-term by changing ModelBinder to create the primary key on-demand if it doesn't exist. https://github.com/rtennantventuretech/hibernate-orm/commit/c2bf4b808259c8a56bc494ece7a4ba50874793ec
By default Hibernate will process the HBM mappings before it processes annotation mappings.
Can you specify the following property in your hibernate configuration:
This will basically tell Hibernate to process classes before hbm.
Does changing the precedence order resolve your issue without a code modification?
Thanks for the tip. I tried it by adding
but I still get an exception in ModelBinder. The stack trace is slightly different though.
, I am thinking that entire block where its giving the NullPointerException can probably be removed. Looking at it on the surface, the if/else block doesn't really appear to be doing anything other than populating two values which are never used with the new ImplicitBasicColumnNameSource inline class implementation. I'm going to do some tests, but I think ultimately, that's going to be the right course of action.
Thanks for fixing this Chris. I appreciate it.
Fixed in 5.1 branch as well.