History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: HB-1376
Type: Bug Bug
Status: Closed Closed
Resolution: Rejected
Priority: Major Major
Assignee: Unassigned
Reporter: Dave Birch
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Hibernate2

Loader issues in hibernate

Created: 04/Jan/05 10:31 PM   Updated: 05/Jan/05 09:21 AM
Component/s: core
Affects Version/s: 2.1.7, 2.1.8
Fix Version/s: None

Time Tracking:
Not Specified

Environment:
Environment: from 1.x to 2.1.x, MSSQL, Oracle, MySQL, Postgres
Java 1.4.x


 Description  « Hide
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?


 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Christian Bauer - 04/Jan/05 11:31 PM
You are not mapping inheritance correctly. You will have to use a discriminator if you map a class hierarchy to a single table. Please use the user forum.

Gavin King - 05/Jan/05 09:21 AM
Expected behavior of HB2.1.