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

Hibernate JIRA | Dave Birch | 1 decade ago
tip
Do you know that we can give you better hits? Get more relevant results from Samebug’s stack trace search.
  1. 0
  2. 0
  3. 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)
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 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)
  6. 0

    Hibernate WrongClassException ,table per class scheme

    Google Groups | 1 decade ago | Elhanan
    net.sf.hibernate.WrongClassException: Object with id: 37 was not of the specified subclass: com.pnx.underwrite.bo.underwritemodel.PursuitImpl (loaded object was of wrong class)

    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. net.sf.hibernate.WrongClassException

      Object with id: XXX was not of the specified subclass: com.woolly.store.product.DisplayProductVariation (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