EntityManagerFactoryImpl.getIdentifier uses deprecated version of getIdentifier

Description

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).

Environment

Hibernate 5.0.11, Spring Data JPA 1.10.3

Status

Assignee

Steve Ebersole

Reporter

Patrik Bakken

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure