net.sf.hibernate.WrongClassException: Object with id: XXX was not of the specified subclass: com.woolly.store.product.DisplayProduct (loaded object was of wrong class)

Hibernate JIRA | Dave Birch | 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

    I have 2 classes, Product (for core product info) and DisplayProduct (has extra fields) which is a subclass of Product. Display product is read only & used as a data aggregation class, i *could* load the product instance & then copy to a DisplayProduct instance, but it means 2x overhead for something desired to be an optimisation, i.e. not a great solution. What happens is the loader gets confused & after loading an instance of one class, i can not load an instance of the other, yes they are both mapped to one table, share the same key & one is a subclass, but they are not the same object in the context of the application. I get the following error: <snip> net.sf.hibernate.WrongClassException: Object with id: XXX was not of the specified subclass: com.woolly.store.product.DisplayProduct (loaded object was of wrong class) at net.sf.hibernate.loader.Loader.instanceAlreadyLoaded(Loader.java:531) </snip> samplecode from classes: class Product { private String code; private String description; ... //getters/setters etc ... } and; class DisplayProduct extends Product { private List images; private BigDecimal price; ... //getters/setters etc ... } If i map both of these classes to the same table; <class name="Product" table="str_products"> <id name="code" unsaved-value="null"> <generator class="assigned"/> </id> <version name="version" type="int"/> <property name="name"/> <property name="description"/> <property name="taxCode"/> ... </class> and <class name="DisplayProduct" table="str_products" mutable="false"> <id name="code" unsaved-value="null"> <generator class="assigned"/> </id> <property name="name"/> <property name="description"/> <property name="taxCode"/> ... </class> I have tried switching off the secondary level cache, but the problem seems to run deeper than this. (assuming that setting hibernate.cache.use_second_level_cache=false to do this.) Ideas?

    Hibernate JIRA | 1 decade ago | Dave Birch
    net.sf.hibernate.WrongClassException: Object with id: XXX was not of the specified subclass: com.woolly.store.product.DisplayProduct (loaded object was of wrong class)
  2. 0

    I have 2 classes, Product (for core product info) and DisplayProduct (has extra fields) which is a subclass of Product. Display product is read only & used as a data aggregation class, i *could* load the product instance & then copy to a DisplayProduct instance, but it means 2x overhead for something desired to be an optimisation, i.e. not a great solution. What happens is the loader gets confused & after loading an instance of one class, i can not load an instance of the other, yes they are both mapped to one table, share the same key & one is a subclass, but they are not the same object in the context of the application. I get the following error: <snip> net.sf.hibernate.WrongClassException: Object with id: XXX was not of the specified subclass: com.woolly.store.product.DisplayProduct (loaded object was of wrong class) at net.sf.hibernate.loader.Loader.instanceAlreadyLoaded(Loader.java:531) </snip> samplecode from classes: class Product { private String code; private String description; ... //getters/setters etc ... } and; class DisplayProduct extends Product { private List images; private BigDecimal price; ... //getters/setters etc ... } If i map both of these classes to the same table; <class name="Product" table="str_products"> <id name="code" unsaved-value="null"> <generator class="assigned"/> </id> <version name="version" type="int"/> <property name="name"/> <property name="description"/> <property name="taxCode"/> ... </class> and <class name="DisplayProduct" table="str_products" mutable="false"> <id name="code" unsaved-value="null"> <generator class="assigned"/> </id> <property name="name"/> <property name="description"/> <property name="taxCode"/> ... </class> I have tried switching off the secondary level cache, but the problem seems to run deeper than this. (assuming that setting hibernate.cache.use_second_level_cache=false to do this.) Ideas?

    Hibernate JIRA | 1 decade ago | Dave Birch
    net.sf.hibernate.WrongClassException: Object with id: XXX was not of the specified subclass: com.woolly.store.product.DisplayProduct (loaded object was of wrong class)
  3. 0
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Root Cause Analysis

    1. net.sf.hibernate.WrongClassException

      Object with id: XXX was not of the specified subclass: com.woolly.store.product.DisplayProduct (loaded object was of wrong class)

      at net.sf.hibernate.loader.Loader.instanceAlreadyLoaded()
    2. net.sf.hibernate
      Loader.instanceAlreadyLoaded
      1. net.sf.hibernate.loader.Loader.instanceAlreadyLoaded(Loader.java:531)
      1 frame