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

Hibernate JIRA | Mike G | 6 months ago
tip
Click on the to mark the solution that helps you, Samebug will learn from it.
As a community member, you’ll be rewarded for you help.
  1. 0

    Hello, Following my observations from [link |https://forum.hibernate.org/viewtopic.php?p=2490445#p2490445] 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. java.lang.ClassCastException: org.hibernate.bytecode.enhance.spi.LazyPropertyInitializer$1 cannot be cast to [B at org.hibernate.type.descriptor.java.PrimitiveByteArrayTypeDescriptor.areEqual(PrimitiveByteArrayTypeDescriptor.java:26) at org.hibernate.type.AbstractStandardBasicType.isEqual(AbstractStandardBasicType.java:195) at org.hibernate.type.AbstractStandardBasicType.getReplacement(AbstractStandardBasicType.java:75) at org.hibernate.type.AbstractStandardBasicType.replace(AbstractStandardBasicType.java:361) at org.hibernate.type.TypeHelper.replace(TypeHelper.java:211) at org.hibernate.event.internal.DefaultMergeEventListener.copyValues(DefaultMergeEventListener.java:430) at org.hibernate.event.internal.DefaultMergeEventListener.entityIsTransient(DefaultMergeEventListener.java:232) at org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:172) at org.hibernate.internal.SessionImpl.fireMerge(SessionImpl.java:881) at org.hibernate.internal.SessionImpl.merge(SessionImpl.java:848) at org.hibernate.engine.spi.CascadingActions$6.cascade(CascadingActions.java:261) at org.hibernate.engine.internal.Cascade.cascadeToOne(Cascade.java:391) at org.hibernate.engine.internal.Cascade.cascadeAssociation(Cascade.java:316) at org.hibernate.engine.internal.Cascade.cascadeProperty(Cascade.java:155) at org.hibernate.engine.internal.Cascade.cascade(Cascade.java:104) at org.hibernate.event.internal.AbstractSaveEventListener.cascadeAfterSave(AbstractSaveEventListener.java:445) at org.hibernate.event.internal.DefaultMergeEventListener.entityIsTransient(DefaultMergeEventListener.java:238) at org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:172) at org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:68) at org.hibernate.internal.SessionImpl.fireMerge(SessionImpl.java:857) at org.hibernate.internal.SessionImpl.merge(SessionImpl.java:838) at org.hibernate.internal.SessionImpl.merge(SessionImpl.java:843) at org.hibernate.bugs.ORMUnitTestCase.hhh123Test(ORMUnitTestCase.java:88) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) at org.hibernate.testing.junit4.ExtendedFrameworkMethod.invokeExplosively(ExtendedFrameworkMethod.java:45) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) at org.junit.internal.runners.statements.FailOnTimeout$StatementThread.run(FailOnTimeout.java:74) 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 Code: else if ( target[i] == LazyPropertyInitializer.UNFETCHED_PROPERTY ) { if ( types[i].isMutable() ) { copied[i] = types[i].deepCopy( original[i], session.getFactory() ); } else { copied[i] = original[i]; } } 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

    Hibernate JIRA | 6 months ago | Mike G
    java.lang.ClassCastException: org.hibernate.bytecode.enhance.spi.LazyPropertyInitializer$1 cannot be cast to [B
  2. 0

    Hibernate Community • View topic - @Basic(fetch = FetchType.LAZY) returns null despite hints

    hibernate.org | 4 months ago
    java.lang.ClassCastException: org.hibernate.bytecode.enhance.spi.LazyPropertyInitializer$1 cannot be cast to [B
  3. 0

    [GSS] (6.4.z) HHH-5255, HHH-7573 - ClassCastException on lazy properties when merging or flushing with PreUpdate callback

    https://bugzilla.redhat.com/bugzilla/ | 1 year ago | Stephen Fikes
    java.lang.ClassCastException: org.hibernate.bytecode.instrumentation.spi.LazyPropertyInitializer$1 cannot be cast to [B
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.ClassCastException

      org.hibernate.bytecode.enhance.spi.LazyPropertyInitializer$1 cannot be cast to [B

      at org.hibernate.type.descriptor.java.PrimitiveByteArrayTypeDescriptor.areEqual()
    2. Hibernate
      SessionImpl.merge
      1. org.hibernate.type.descriptor.java.PrimitiveByteArrayTypeDescriptor.areEqual(PrimitiveByteArrayTypeDescriptor.java:26)
      2. org.hibernate.type.AbstractStandardBasicType.isEqual(AbstractStandardBasicType.java:195)
      3. org.hibernate.type.AbstractStandardBasicType.getReplacement(AbstractStandardBasicType.java:75)
      4. org.hibernate.type.AbstractStandardBasicType.replace(AbstractStandardBasicType.java:361)
      5. org.hibernate.type.TypeHelper.replace(TypeHelper.java:211)
      6. org.hibernate.event.internal.DefaultMergeEventListener.copyValues(DefaultMergeEventListener.java:430)
      7. org.hibernate.event.internal.DefaultMergeEventListener.entityIsTransient(DefaultMergeEventListener.java:232)
      8. org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:172)
      9. org.hibernate.internal.SessionImpl.fireMerge(SessionImpl.java:881)
      10. org.hibernate.internal.SessionImpl.merge(SessionImpl.java:848)
      11. org.hibernate.engine.spi.CascadingActions$6.cascade(CascadingActions.java:261)
      12. org.hibernate.engine.internal.Cascade.cascadeToOne(Cascade.java:391)
      13. org.hibernate.engine.internal.Cascade.cascadeAssociation(Cascade.java:316)
      14. org.hibernate.engine.internal.Cascade.cascadeProperty(Cascade.java:155)
      15. org.hibernate.engine.internal.Cascade.cascade(Cascade.java:104)
      16. org.hibernate.event.internal.AbstractSaveEventListener.cascadeAfterSave(AbstractSaveEventListener.java:445)
      17. org.hibernate.event.internal.DefaultMergeEventListener.entityIsTransient(DefaultMergeEventListener.java:238)
      18. org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:172)
      19. org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:68)
      20. org.hibernate.internal.SessionImpl.fireMerge(SessionImpl.java:857)
      21. org.hibernate.internal.SessionImpl.merge(SessionImpl.java:838)
      22. org.hibernate.internal.SessionImpl.merge(SessionImpl.java:843)
      22 frames
    3. org.hibernate.bugs
      ORMUnitTestCase.hhh123Test
      1. org.hibernate.bugs.ORMUnitTestCase.hhh123Test(ORMUnitTestCase.java:88)
      1 frame
    4. Java RT
      Method.invoke
      1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      2. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      3. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      4. java.lang.reflect.Method.invoke(Method.java:498)
      4 frames
    5. JUnit
      FrameworkMethod.invokeExplosively
      1. org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
      2. org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      3. org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
      3 frames
    6. A Hibernate O/RM Module
      ExtendedFrameworkMethod.invokeExplosively
      1. org.hibernate.testing.junit4.ExtendedFrameworkMethod.invokeExplosively(ExtendedFrameworkMethod.java:45)
      1 frame
    7. JUnit
      FailOnTimeout$StatementThread.run
      1. org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
      2. org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
      3. org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
      4. org.junit.internal.runners.statements.FailOnTimeout$StatementThread.run(FailOnTimeout.java:74)
      4 frames