| 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) |