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

Hibernate JIRA | Arthur Noseda | 2 years ago
tip
Do you know that we can give you better hits? Get more relevant results from Samebug’s stack trace search.
  1. 0

    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.

    Hibernate JIRA | 2 years ago | Arthur Noseda
    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
  2. 0

    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.

    Hibernate JIRA | 2 years ago | Arthur Noseda
    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

    Root Cause Analysis

    1. 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()
    2. Hibernate
      FieldInterceptorImpl.readObject
      1. org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:134)
      2. org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1070)
      3. org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:989)
      4. org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:716)
      5. org.hibernate.type.ManyToOneType.assemble(ManyToOneType.java:282)
      6. org.hibernate.persister.entity.AbstractEntityPersister.initializeLazyPropertiesFromCache(AbstractEntityPersister.java:1333)
      7. org.hibernate.persister.entity.AbstractEntityPersister.initializeLazyProperty(AbstractEntityPersister.java:1244)
      8. org.hibernate.bytecode.instrumentation.spi.AbstractFieldInterceptor.intercept(AbstractFieldInterceptor.java:112)
      9. org.hibernate.bytecode.instrumentation.internal.javassist.FieldInterceptorImpl.readObject(FieldInterceptorImpl.java:91)
      9 frames
    3. demo.domain
      OrderLine.getOrder
      1. demo.domain.OrderLine.$javassist_read_order(OrderLine.java)
      2. demo.domain.OrderLine.getOrder(OrderLine.java:54)
      2 frames
    4. demo
      AppTest$2.doWithinTransaction
      1. demo.AppTest$2.doWithinTransaction(AppTest.java:47)
      1 frame
    5. demo.utils
      HibernateTemplate.execute
      1. demo.utils.HibernateTemplate.execute(HibernateTemplate.java:21)
      1 frame
    6. demo
      AppTest.shouldFailToResolveEntityName
      1. demo.AppTest.shouldFailToResolveEntityName(AppTest.java:41)
      1 frame