Hibernate version:
3
Mapping documents:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping default-lazy="false" default-cascade="all-delete-orphan">
<class name="Interpret" table="interprets">
<id name="persistenceId" column="id" unsaved-value="0" type="java.lang.Long">
<generator class="increment"/>
</id>
<discriminator column="type" type="java.lang.String"/>
<map name="levelsAsMap" table="interpret_levels">
<key column="interpret_id" not-null="true"/>
<map-key column="level" type="java.lang.String"/>
<element column="value" type="java.lang.Double" not-null="true"/>
</map>
<subclass name="AscendingInterpret" discriminator-value="ascending">
</subclass>
<subclass name="DescendingInterpret" discriminator-value="descending">
</subclass>
<subclass name="BandInterpret" discriminator-value="band">
</subclass>
</class>
</hibernate-mapping>
Name and version of the database you are using:MySQL
Description of the problem:I have an abstract Interpret class. When I create a concrete interpret (Ascending/Descending/...) and I save it to the database the object is saved correctly. Loading works fine too. But in the client application I also need to change interpret's type when needed. Here comes the problem. Hibernate doesn't save the changes to the discriminator value. It updates correctly the level map but the type column contains always the type of the first object saved.
What is specific is that I preserve the persistence ID and try to save the new object (which is of different concrete class). If I create a new object each time there is a problem with another mapping in the hierarchy. I have a Personal Interpret which uses the persistance ID of the interpret like this:
Code:
<id name="persistenceId" column="id" unsaved-value="0" type="java.lang.Long">
<generator class="foreign">
<param name="property">interpret</param>
</generator>
</id>
When I save the interpret as a new object the PersonalInterpret's ID doesn't follow the change and is left linked with the first interpret. Anyway I would like to work with the old persistance ID and change only the type class. This way I have less things to do.
I thought about using property instead of discriminator but I could not really change the class type in the load.
So, finally, anyone has an idea why Hibernate doesn't change the discriminator-value when the subclass changes it's type?