Hello,
I implement "Table per class hierarchy".
If I have in my table one row that describes a "MUERTO" item and I would like to convert him to "EJEMPLAR" without change his "Id"...
How can I make it?
I've tried:
Ejemplar e = ...load(Muerto...., id); ----------->error
Muerto m = ...load(Muerto...., id);
Ejemplar e = (Ejemplar) m; ------------>error
if I load MUERTO, make instance of Ejemplar, copy all atributes, delete MUERTO and save Ejemplar, the Id changes because it is assigned automaticly by the database.
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>
<class name="org.modelo.Ejemplar" table="EJEMPLAR" discriminator-value="E">
<id name="Id" type="java.lang.Integer">
<column name="ID" not-null="true" unique="true" sql-type="INTEGER" />
<generator class="identity" />
</id>
<discriminator column="type" type="character"/>
<many-to-one name="Criador" class="org.modelo.Persona">
<column name="CRIADOR" not-null="false" />
</many-to-one>
<many-to-one name="Propietario" class="org.modelo.Persona">
<column name="PROPIETARIO" not-null="false" />
</many-to-one>
<many-to-one name="Raza" class="org.modelo.Raza">
<column name="RAZA" not-null="true" />
</many-to-one>
(...)
<subclass name="org.modelo.Muerto" discriminator-value="M">
<property name="Fechadef" type="java.lang.String">
<column name="FECHADEF" not-null="true" sql-type="VARCHAR" />
</property>
<property name="Motivo" type="java.lang.String">
<column name="MOTIVO" not-null="false" sql-type="VARCHAR" />
</property>
</subclass>
</class>
</hibernate-mapping>
Thank you very much.