org.hibernate.WrongClassException: Object [id=4010] was not of the specified subclass [B2] : loaded object was of wrong class class B1

Hibernate JIRA | Sergiu Hlihor | 6 months ago
  1. 0

    In order optimize the load time of our entities, we set the default_batch_fetch_size to 256 (previously the value was not set at all). Now during a specific operation in which we load a set of entities, some of them with eager loading and some of them with lazy loading, we get the exception from below. The data model is the following: A - entity B1 and B2 entities where B2 extends B1 and both B1 and B2 are stored in same table but differentiated by DTYPE C - entity Entity A contains a list of B1 and B2 entities (eager loading) and only B2 contains a list of C entities which are lazy loaded. The exception happens when loading all A entities at once and going through B1/B2 list and trying to access first entity from list of C entities (which for that specific case are loaded lazily). When debugged, the object referenced in exception is totally unrelated to the entity accessed. The stacktrace was generated using Hibernate 4.3.5, however the issue is also reproducible on 4.3.11 org.hibernate.WrongClassException: Object [id=4010] was not of the specified subclass [B2] : loaded object was of wrong class class B1 at org.hibernate.loader.Loader.instanceAlreadyLoaded(Loader.java:1550) at org.hibernate.loader.Loader.getRow(Loader.java:1503) at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:725) at org.hibernate.loader.Loader.processResultSet(Loader.java:952) at org.hibernate.loader.Loader.doQuery(Loader.java:920) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:354) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:324) at org.hibernate.loader.Loader.loadCollectionBatch(Loader.java:2299) at org.hibernate.loader.collection.plan.LegacyBatchingCollectionInitializerBuilder$LegacyBatchingCollectionInitializer.initialize(LegacyBatchingCollectionInitializerBuilder.java:100) at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:693) at org.hibernate.event.internal.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:92) at org.hibernate.internal.SessionImpl.initializeCollection(SessionImpl.java:1897) at org.hibernate.collection.internal.AbstractPersistentCollection$4.doWork(AbstractPersistentCollection.java:558) at org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:260) at org.hibernate.collection.internal.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:554) at org.hibernate.collection.internal.AbstractPersistentCollection.read(AbstractPersistentCollection.java:142) at org.hibernate.collection.internal.PersistentBag.get(PersistentBag.java:466)

    Hibernate JIRA | 6 months ago | Sergiu Hlihor
    org.hibernate.WrongClassException: Object [id=4010] was not of the specified subclass [B2] : loaded object was of wrong class class B1
  2. 0

    In order optimize the load time of our entities, we set the default_batch_fetch_size to 256 (previously the value was not set at all). Now during a specific operation in which we load a set of entities, some of them with eager loading and some of them with lazy loading, we get the exception from below. The data model is the following: A - entity B1 and B2 entities where B2 extends B1 and both B1 and B2 are stored in same table but differentiated by DTYPE C - entity Entity A contains a list of B1 and B2 entities (eager loading) and only B2 contains a list of C entities which are lazy loaded. The exception happens when loading all A entities at once and going through B1/B2 list and trying to access first entity from list of C entities (which for that specific case are loaded lazily). When debugged, the object referenced in exception is totally unrelated to the entity accessed. The stacktrace was generated using Hibernate 4.3.5, however the issue is also reproducible on 4.3.11 org.hibernate.WrongClassException: Object [id=4010] was not of the specified subclass [B2] : loaded object was of wrong class class B1 at org.hibernate.loader.Loader.instanceAlreadyLoaded(Loader.java:1550) at org.hibernate.loader.Loader.getRow(Loader.java:1503) at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:725) at org.hibernate.loader.Loader.processResultSet(Loader.java:952) at org.hibernate.loader.Loader.doQuery(Loader.java:920) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:354) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:324) at org.hibernate.loader.Loader.loadCollectionBatch(Loader.java:2299) at org.hibernate.loader.collection.plan.LegacyBatchingCollectionInitializerBuilder$LegacyBatchingCollectionInitializer.initialize(LegacyBatchingCollectionInitializerBuilder.java:100) at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:693) at org.hibernate.event.internal.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:92) at org.hibernate.internal.SessionImpl.initializeCollection(SessionImpl.java:1897) at org.hibernate.collection.internal.AbstractPersistentCollection$4.doWork(AbstractPersistentCollection.java:558) at org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:260) at org.hibernate.collection.internal.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:554) at org.hibernate.collection.internal.AbstractPersistentCollection.read(AbstractPersistentCollection.java:142) at org.hibernate.collection.internal.PersistentBag.get(PersistentBag.java:466)

    Hibernate JIRA | 6 months ago | Sergiu Hlihor
    org.hibernate.WrongClassException: Object [id=4010] was not of the specified subclass [B2] : loaded object was of wrong class class B1
  3. 0

    Loaded object was of wrong class

    Google Groups | 7 years ago | Tony Nelson
    org.hibernate.WrongClassException: Object with id: 1 was not of the specified subclass: Category (loaded object was of wrong class class coldfusion.orm.PersistentTemplateProxy)
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    What may be causing this WrongClassException Hibernate

    Stack Overflow | 3 years ago | StudioWorks
    org.hibernate.WrongClassException: Object with id: 3 was not of the specified subclass: br.com.wplex.cccw.bo.DadosDeCobrancaBO (loaded object was of wrong class class br.com.wplex.cccw.bo.ClienteBO)
  6. 0

    Object with id was not of the specified subclass

    Stack Overflow | 2 years ago | Alberson Melo
    org.hibernate.WrongClassException: Object with id: 11952 was not of the specified subclass: VtigerAccountbillads (loaded object was of wrong class class VtigerAccountshipads)

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. org.hibernate.WrongClassException

      Object [id=4010] was not of the specified subclass [B2] : loaded object was of wrong class class B1

      at org.hibernate.loader.Loader.instanceAlreadyLoaded()
    2. Hibernate
      Loader.loadCollectionBatch
      1. org.hibernate.loader.Loader.instanceAlreadyLoaded(Loader.java:1550)
      2. org.hibernate.loader.Loader.getRow(Loader.java:1503)
      3. org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:725)
      4. org.hibernate.loader.Loader.processResultSet(Loader.java:952)
      5. org.hibernate.loader.Loader.doQuery(Loader.java:920)
      6. org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:354)
      7. org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:324)
      8. org.hibernate.loader.Loader.loadCollectionBatch(Loader.java:2299)
      8 frames
    3. org.hibernate.loader
      LegacyBatchingCollectionInitializerBuilder$LegacyBatchingCollectionInitializer.initialize
      1. org.hibernate.loader.collection.plan.LegacyBatchingCollectionInitializerBuilder$LegacyBatchingCollectionInitializer.initialize(LegacyBatchingCollectionInitializerBuilder.java:100)
      1 frame
    4. Hibernate
      PersistentBag.get
      1. org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:693)
      2. org.hibernate.event.internal.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:92)
      3. org.hibernate.internal.SessionImpl.initializeCollection(SessionImpl.java:1897)
      4. org.hibernate.collection.internal.AbstractPersistentCollection$4.doWork(AbstractPersistentCollection.java:558)
      5. org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:260)
      6. org.hibernate.collection.internal.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:554)
      7. org.hibernate.collection.internal.AbstractPersistentCollection.read(AbstractPersistentCollection.java:142)
      8. org.hibernate.collection.internal.PersistentBag.get(PersistentBag.java:466)
      8 frames