Query using detached Proxy as parameter fails with LazyInitializationException

Description

If the query parameter value contains a uninitialized proxy bean, exuting the query fails with
'org.hibernate.LazyInitializationException: could not retrieve real entity class [org.example.testcase.model.Department#1] - no Session'

  • full stacktrace below.

No error with versions 6.2.x and 6.4.1 (6.3.x not tested)

I suspect the changes in class EntityJavaType cause this error. Method isInstance calls Hibernate.getClassLazy with requires a session for resolving the class type. Enabling config setting 'hibernate.enable_lazy_load_no_trans=true' does not help.

In my opinion, these changes are relatively critical as they can lead to unpredictable errors after the upgrade.

I have attached a simple testcase to reproduce this error.

kind regards

Attachments

1

Activity

Show:

Andrea Boriero February 5, 2024 at 12:40 PM
Edited

Hi ,

this happens because Hibernate is trying to validate the parameter and to do this it needs to know the class of the proxy, I’m creating a PR that tries to avoid to initialize the proxy in most of the cases but keep in mind that with inheritance this is not always possible.

My advice is to use the id of the department

instead of

Robert Thaler February 2, 2024 at 1:50 PM

yes, provided testcase uses 6.4.3.Final

Gavin King February 2, 2024 at 1:21 PM

Have you tried 6.4.3?

Fixed

Details

Assignee

Reporter

Worked in

Sprint

Fix versions

Affects versions

Priority

Created February 2, 2024 at 1:07 PM
Updated February 8, 2024 at 1:15 PM
Resolved February 8, 2024 at 11:07 AM