TypeMismatchException when getting a 2nd-level cached entity through a lazy-to-one relation

Description

The attached document is a stand-alone test case with HSQLDB 2.3.2, Hibernate 4.3.8.Final and ehcache 2.6.9, although the situation initially happened in an Oracle 10g / Hibernate 4.3.7.Final / ehcache 2.6.9 application.

When an entity is cached and related to another through a lazy-to-one relation, getting this entity throws a TypeMismatchException.

For example, with Order and OrderLine both instrumented and cached entities, OrderLine being related to Order through an @LazyToOne property, when executing these few lines,

List<OrderLine> orderLines = sess.createCriteria(OrderLine.class).list();
for (OrderLine orderLine : orderLines) {
System.out.println(orderLine.getOrder());
}

I get

org.hibernate.TypeMismatchException: Provided id of the wrong type for class demo.domain.Order. Expected: class java.lang.Long, got class org.hibernate.bytecode.instrumentation.spi.LazyPropertyInitializer$1
at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:134)
at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1070)
at org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:989)
at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:716)
at org.hibernate.type.ManyToOneType.assemble(ManyToOneType.java:282)
at org.hibernate.persister.entity.AbstractEntityPersister.initializeLazyPropertiesFromCache(AbstractEntityPersister.java:1333)
at org.hibernate.persister.entity.AbstractEntityPersister.initializeLazyProperty(AbstractEntityPersister.java:1244)
at org.hibernate.bytecode.instrumentation.spi.AbstractFieldInterceptor.intercept(AbstractFieldInterceptor.java:112)
at org.hibernate.bytecode.instrumentation.internal.javassist.FieldInterceptorImpl.readObject(FieldInterceptorImpl.java:91)
at demo.domain.OrderLine.$javassist_read_order(OrderLine.java)
at demo.domain.OrderLine.getOrder(OrderLine.java:54)
at demo.AppTest$2.doWithinTransaction(AppTest.java:47)
at demo.utils.HibernateTemplate.execute(HibernateTemplate.java:21)
at demo.AppTest.shouldFailToResolveEntityName(AppTest.java:41)

This is also the case when working with an EntityManager instead of an Hibernate Session.

Attachments

2

Activity

Show:

Gavin King November 29, 2024 at 6:03 AM

LazyToOne was removed.

Learner Evermore June 15, 2018 at 7:44 PM
Edited

I am facing the same issue (4.3.11.Final). We are forced to either disable caching or not use lazy loading, neither one of which is desirable. Is there any progress?

Arthur Noseda November 5, 2015 at 5:43 PM

I uploaded the updated version of the test case. I also downgraded EHCACHE to version 2.4.3 to match with the version packaged inside hibernate-release-5.0.2.Final.zip.

Steve Ebersole October 28, 2015 at 3:25 AM

As part of verifying that this issue affects 5.0, please just set the "Affects version". Leave the "verify-affects-5.0" label and leave the issue in "Awaiting Response" status; these are critical for us to be able to track these verifications and triage them. Thanks.

Steve Ebersole October 27, 2015 at 7:16 PM

This bug report does not indicate that the reported issue affects version 5.x. Versions prior to 5.x are no longer maintained. It would be a great help to the Hibernate team and community for someone to verify that the reported issue still affects version 5.x. If so, please add the 5.x version that you verified with to the list of affected-versions and attach the (preferably SSCCE) test case you used to do the verification to the report; from there the issues will be looked at during our triage meetings.

For details, see http://in.relation.to/2015/10/27/great-jira-cleanup-2015/

Out of Date

Details

Assignee

Reporter

Labels

Components

Affects versions

Priority

Created January 13, 2015 at 2:25 PM
Updated December 3, 2024 at 9:20 AM
Resolved November 29, 2024 at 6:03 AM