When trying to get the identifier of an entity from the PersistenceUnitUtil, I get a NullPointerException. This is because the implementation of getIdentifier uses the deprecated version of ClassMetadata.getIdentifier() which takes no session, and subsequently the implementation of it explicitly sets the session to null. When you get to the IncrediblySillyJpaMapsIdMappedIdentifierValueMarshaller.getIdentifier()-method, persistEventListeners( session ) is called, which then throws the NullPointerException.
This problem is documented as such:
However, this happens after the persistEventListeners( session )-call. Shouldn't the new version of getIdentifier() be used when there already is support for this in the code?
The implementation of PersistenceUnitUtil.getIdentifier() in EntityManagerFactoryImpl::HibernatePersistenceUnitUtil:
Side note: I can see there is a "TODO:"-comment here, and the answer is no. This has to do with the problem in HHH-10623. It should work for simple IdClass'es though (with no ManyToOne-relationships in the IdClass).
Hibernate 5.0.11, Spring Data JPA 1.10.3