LazyPropertyInitializer$1 cannot be cast to [B when calling Session.merge() on compile time enhanced composed entities

Description

Hello,

Following my observations from link I open this ticket as instructed on same topic.

Basically I have 2 Hibernate persistent entities Company, Manager ("has a" relationship).
Manager.resume is annotated with (@Basic(fetch = FetchType.LAZY)). Both entity classes are compile time instrumented by org.hibernate.orm.tooling:hibernate-enhance-maven-plugin.

At runtime during the transactional/Hibernate session scope:

  • create new instance Company/Manager

  • assemble them (they are still transient)

  • try to call session.merge(company). Following this I get the error below.
    The use case can be reproduced with the attached test case.

As I said in the post, by debugging and checking your github fixes for hibernate 4.x on same error:
Maybe a solution would be to modify the following method ? org.hibernate.type.TypeHelper.replace(Object[], Object[], Type[], SharedSessionContractImplementor, Object, Map, ForeignKeyDirection))

by adding a condition like you did when fixing the other

just as you did with the other one: org.hibernate.type.TypeHelper.replace(Object[], Object[], Type[], SharedSessionContractImplementor, Object, Map) in pull 891 https://github.com/hibernate/hibernate-orm/pull/891/files

I think this method is called for MyEntity properties (org.hibernate.type.TypeHelper.replace(Object[], Object[], Type[], SharedSessionContractImplementor, Object, Map, ForeignKeyDirection))) because I am persisting MyEntity indirectly through a parent entity MyContainerEntity (one-to-one relation, MyEntity being the owning side).

So the particularity of this case is that that a child entity fails to get merged through a parent entity. The child entity is compile time instrumented and has a LAZY Basic attribute/property.

Thanks in advance for looking

Environment

Java 1.8
<version.com.h2database>1.3.176</version.com.h2database>
<version.junit>4.11</version.junit>
<version.org.hibernate>5.2.1.Final</version.org.hibernate> / 5.2.2.Final
<version.org.slf4j>1.7.2</version.org.slf4j>
org.hibernate.orm.tooling:hibernate-enhance-maven-plugin:5.2.1.Final / 5.2.2.Final

Activity

Show:
Giovanni Lovato
September 29, 2016, 3:25 PM

I have a similar issue with 5.2.2 and it may be related: when loading an enhanced Entity which has a field annotated with @OneToOne(mappedBy = "...", fetch = LAZY) and @LazyToOne(NO_PROXY) using EM.find(Class, key), I get this Exception:

java.lang.ClassCastException: org.hibernate.bytecode.enhance.spi.LazyPropertyInitializer$1 cannot be cast to [Ljava.lang.Object;

Giovanni Lovato
February 25, 2017, 8:48 AM
Edited

Comes out my case it indeed different, as it happens only when cache is enabled. I'll open a new issue.

Ioannis Kontogounis
April 21, 2017, 10:59 AM
Edited

I have exactly the same issue on 5.0.10 with a byte[] (blob) of a child entity that is merged through cascade merge from @OneToOne parent entity.
If the lazy byte[] is not initialized before merge, you get the ClassCastException.

Vlad Mihalcea
November 16, 2017, 9:06 AM

This got fixed by HHH-12054.

Assignee

Vlad Mihalcea

Reporter

Mike G

Fix versions

Labels

backPortable

None

Suitable for new contributors

None

Requires Release Note

Affirmative

backportDecision

None

Components

Affects versions

Priority

Major
Configure