net.sf.hibernate.WrongClassException: Object with id: 21 was not of the specified subclass: test.A (loaded object was of wrong class)

Hibernate JIRA | alexander thomas | 1 decade ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    Hello folks, I did not find anything related to this issue on the net so I put it here: Provided are two classes A and B wich are in a 1.) many-to-many relationship 2.) with an association class Association which contains some forther attributes 2.) and is navigable from A to B and from B to A I thried to implement this in hibernate and it works well as long as the navigation goes only in one direction meaning: there is 1.) a public Collection getABAssociatins() method in the A class 2.) a public B getB() method in the Association class At the point where I try to include backwards navigation I run into the following error stack: net.sf.hibernate.WrongClassException: Object with id: 21 was not of the specified subclass: test.A (loaded object was of wrong class) at net.sf.hibernate.loader.Loader.instanceAlreadyLoaded(Loader.java:300) at net.sf.hibernate.loader.Loader.getRow(Loader.java:278) at net.sf.hibernate.loader.Loader.doFind(Loader.java:159) at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:602) at net.sf.hibernate.loader.OneToManyLoader.initialize(OneToManyLoader.java:102) at net.sf.hibernate.impl.SessionImpl.initialize(SessionImpl.java:2897) at net.sf.hibernate.collection.PersistentCollection.getInitialValue(PersistentCollection.java:128) at net.sf.hibernate.type.PersistentCollectionType.getCollection(PersistentCollectionType.java:74) at net.sf.hibernate.type.PersistentCollectionType.resolveIdentifier(PersistentCollectionType.java:177) at net.sf.hibernate.impl.SessionImpl.initializeEntity(SessionImpl.java:1959) at net.sf.hibernate.loader.Loader.doFind(Loader.java:196) at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:602) at net.sf.hibernate.loader.OneToManyLoader.initialize(OneToManyLoader.java:102) at net.sf.hibernate.impl.SessionImpl.initialize(SessionImpl.java:2897) at net.sf.hibernate.collection.PersistentCollection.getInitialValue(PersistentCollection.java:128) at net.sf.hibernate.type.PersistentCollectionType.getCollection(PersistentCollectionType.java:74) at net.sf.hibernate.type.PersistentCollectionType.resolveIdentifier(PersistentCollectionType.java:177) at net.sf.hibernate.impl.SessionImpl.initializeEntity(SessionImpl.java:1959) at net.sf.hibernate.loader.Loader.doFind(Loader.java:196) at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:587) at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:42) at net.sf.hibernate.persister.EntityPersister.load(EntityPersister.java:396) at net.sf.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:1889) at net.sf.hibernate.impl.SessionImpl.doLoadByClass(SessionImpl.java:1757) at net.sf.hibernate.impl.SessionImpl.load(SessionImpl.java:1688) at test.testEnitityToObjectToEntityReferenzes(HibernateTest.java:315) I suppose hibernat does not support this kind of usage (or am I doing something wrong???) and would like to propose this for an improvement. Kindest Regards Alexander Thomas

    Hibernate JIRA | 1 decade ago | alexander thomas
    net.sf.hibernate.WrongClassException: Object with id: 21 was not of the specified subclass: test.A (loaded object was of wrong class)
  2. 0

    Hello folks, I did not find anything related to this issue on the net so I put it here: Provided are two classes A and B wich are in a 1.) many-to-many relationship 2.) with an association class Association which contains some forther attributes 2.) and is navigable from A to B and from B to A I thried to implement this in hibernate and it works well as long as the navigation goes only in one direction meaning: there is 1.) a public Collection getABAssociatins() method in the A class 2.) a public B getB() method in the Association class At the point where I try to include backwards navigation I run into the following error stack: net.sf.hibernate.WrongClassException: Object with id: 21 was not of the specified subclass: test.A (loaded object was of wrong class) at net.sf.hibernate.loader.Loader.instanceAlreadyLoaded(Loader.java:300) at net.sf.hibernate.loader.Loader.getRow(Loader.java:278) at net.sf.hibernate.loader.Loader.doFind(Loader.java:159) at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:602) at net.sf.hibernate.loader.OneToManyLoader.initialize(OneToManyLoader.java:102) at net.sf.hibernate.impl.SessionImpl.initialize(SessionImpl.java:2897) at net.sf.hibernate.collection.PersistentCollection.getInitialValue(PersistentCollection.java:128) at net.sf.hibernate.type.PersistentCollectionType.getCollection(PersistentCollectionType.java:74) at net.sf.hibernate.type.PersistentCollectionType.resolveIdentifier(PersistentCollectionType.java:177) at net.sf.hibernate.impl.SessionImpl.initializeEntity(SessionImpl.java:1959) at net.sf.hibernate.loader.Loader.doFind(Loader.java:196) at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:602) at net.sf.hibernate.loader.OneToManyLoader.initialize(OneToManyLoader.java:102) at net.sf.hibernate.impl.SessionImpl.initialize(SessionImpl.java:2897) at net.sf.hibernate.collection.PersistentCollection.getInitialValue(PersistentCollection.java:128) at net.sf.hibernate.type.PersistentCollectionType.getCollection(PersistentCollectionType.java:74) at net.sf.hibernate.type.PersistentCollectionType.resolveIdentifier(PersistentCollectionType.java:177) at net.sf.hibernate.impl.SessionImpl.initializeEntity(SessionImpl.java:1959) at net.sf.hibernate.loader.Loader.doFind(Loader.java:196) at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:587) at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:42) at net.sf.hibernate.persister.EntityPersister.load(EntityPersister.java:396) at net.sf.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:1889) at net.sf.hibernate.impl.SessionImpl.doLoadByClass(SessionImpl.java:1757) at net.sf.hibernate.impl.SessionImpl.load(SessionImpl.java:1688) at test.testEnitityToObjectToEntityReferenzes(HibernateTest.java:315) I suppose hibernat does not support this kind of usage (or am I doing something wrong???) and would like to propose this for an improvement. Kindest Regards Alexander Thomas

    Hibernate JIRA | 1 decade ago | alexander thomas
    net.sf.hibernate.WrongClassException: Object with id: 21 was not of the specified subclass: test.A (loaded object was of wrong class)

    Root Cause Analysis

    1. net.sf.hibernate.WrongClassException

      Object with id: 21 was not of the specified subclass: test.A (loaded object was of wrong class)

      at net.sf.hibernate.loader.Loader.instanceAlreadyLoaded()
    2. net.sf.hibernate
      SessionImpl.load
      1. net.sf.hibernate.loader.Loader.instanceAlreadyLoaded(Loader.java:300)
      2. net.sf.hibernate.loader.Loader.getRow(Loader.java:278)
      3. net.sf.hibernate.loader.Loader.doFind(Loader.java:159)
      4. net.sf.hibernate.loader.Loader.loadCollection(Loader.java:602)
      5. net.sf.hibernate.loader.OneToManyLoader.initialize(OneToManyLoader.java:102)
      6. net.sf.hibernate.impl.SessionImpl.initialize(SessionImpl.java:2897)
      7. net.sf.hibernate.collection.PersistentCollection.getInitialValue(PersistentCollection.java:128)
      8. net.sf.hibernate.type.PersistentCollectionType.getCollection(PersistentCollectionType.java:74)
      9. net.sf.hibernate.type.PersistentCollectionType.resolveIdentifier(PersistentCollectionType.java:177)
      10. net.sf.hibernate.impl.SessionImpl.initializeEntity(SessionImpl.java:1959)
      11. net.sf.hibernate.loader.Loader.doFind(Loader.java:196)
      12. net.sf.hibernate.loader.Loader.loadCollection(Loader.java:602)
      13. net.sf.hibernate.loader.OneToManyLoader.initialize(OneToManyLoader.java:102)
      14. net.sf.hibernate.impl.SessionImpl.initialize(SessionImpl.java:2897)
      15. net.sf.hibernate.collection.PersistentCollection.getInitialValue(PersistentCollection.java:128)
      16. net.sf.hibernate.type.PersistentCollectionType.getCollection(PersistentCollectionType.java:74)
      17. net.sf.hibernate.type.PersistentCollectionType.resolveIdentifier(PersistentCollectionType.java:177)
      18. net.sf.hibernate.impl.SessionImpl.initializeEntity(SessionImpl.java:1959)
      19. net.sf.hibernate.loader.Loader.doFind(Loader.java:196)
      20. net.sf.hibernate.loader.Loader.loadEntity(Loader.java:587)
      21. net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:42)
      22. net.sf.hibernate.persister.EntityPersister.load(EntityPersister.java:396)
      23. net.sf.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:1889)
      24. net.sf.hibernate.impl.SessionImpl.doLoadByClass(SessionImpl.java:1757)
      25. net.sf.hibernate.impl.SessionImpl.load(SessionImpl.java:1688)
      25 frames
    3. Unknown
      test.testEnitityToObjectToEntityReferenzes
      1. test.testEnitityToObjectToEntityReferenzes(HibernateTest.java:315)
      1 frame