Skip to content

Disable Hibernate entity scanning for default JPA setup #15321

@odrotbohm

Description

@odrotbohm

As apparent from Hibernate's MetadataBuildingProcess, it insists on re-scanning a persistence unit's root URL, even if that already has managed classes defined and configured. In case of that scan picking up an AttributeConverter implementation, this is currently directly instantiated (see ScanningCoordinator.applyScanResultsToManagedResources(…) and thus bypasses the managed bean integration Spring provides and Boot configures.

In cases in which the reflection based instantiation of the AttributeConverter fails, this will break the startup process and the user is left wondering why SpringBeanContainer does not handle that instance. Even worse, in case the reflection based instantiation works, the user is left with an instance that didn't get any dependencies injected.

There's a Hibernate property that can be set to disable Hibernate's own entity scanning, which – independent of whether Hibernate moves to a managed bean aware processing of the scan result – we should be able to use safely, as our default setup configures a fully prepared persistence unit, so that the (re)scanning is not actually needed. This also improves Hibernate bootstrap performance in the context of a Boot app.

Here's an example of how I worked around this issue in a concrete project.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions