Mixing <Joined-subclass> and <subclass>
I'm actually adding a functionality in a product (Hibernate & Spring intensive use) and I have to modify the actual Hibernate mapping, here's the deal :
the "Mother"
entity (abstract) class and called AbstractElement
<class abstract="true" dynamic-insert="true" dynamic-update="true" name="fr.g.n.a.domain.instances.AbstractElement"
table="AEL_ABSTRACT_ELEMENT">
<cache usage="read-write" />
<id name="oid" type="string">
<column length="64" name="OID" />
<generator class="assigned" />
</id>
<discriminator column="TYPELEMENT" type="string" not-null="false" force="true" />
<!-- Version hibernate de l'objet persisté : -1 signifie que l'objet n'est pas présent en base -->
<version name="version" unsaved-value="negative">
<column name="VERSION" />
</version>
a sub class (not abstract) which enhances the concept called "ElementNiveauUn"
, here's a snippet of it mapping
<joined-subclass dynamic-insert="true" dynamic-update="true" name="fr.g.n.a.domain.instances.ElementNiveauUn"
table="ENU_ELEMENT_NIVEAU_UN" abstract="true" lazy="false" extends="fr.generali.nova.atp.domain.instances.AbstractElement">
<key column="OID" not-null="true" foreign-key="FK_ENU_AEL_OID" />
until here, every thing is running well, nothing special to mention about the java classes, here's my problem :
I have to add a class (non abstract) which extends ElementNiveauUn
in order to inherit from it, and so from "AbstractElement"
.
The snippet of the mapping looks like this:
<subclass name="fr.g.n.a.domain.parametrage.Critere" extends="fr.g.n.a.domain.instances.ElementNiveauUn" >
<subclass dynamic-insert="true" dynamic-update="true" name="fr.g.n.a.parametrage.CritereProduit" abstract="false" lazy="false"
extends="fr.g.n.a.domain.parametrage.Critere" discriminator-value="CRITERE_PRODUIT">
</subclass>
<subclass dynamic-insert="true" dynamic-update="true" name="fr.g.n.a.domain.parametrage.Segmentation" abstract="false" lazy="false"
extends="fr.g.n.a.atp.domain.parametrage.Critere" discriminator-value="SEGMENTATION">
</subclass>
<subclass dynamic-insert="true" dynamic-update="true" name="fr.g.n.a.domain.parametrage.CritereApporteur" abstract="false" lazy="false"
extends="fr.g.n.a.atp.domain.parametrage.Critere" discriminator-value="CRITERE_APPORTEUR">
</subclass>
when I try to save an instance of Segmentation I have this kind of Exception (using H2 and UDBUnit)
Caused by: org.h2.jdbc.JdbcSQLException: NULL not allowed for column "ID_ELEMENT_NIVEAU_UN"; SQL statement: insert into ENU_E开发者_开发问答LEMENT_NIVEAU_UN (OID) values (?) [23502-154]
and the generated SQL for the insertion of Segmentation looks like this
insert into ENU_ELEMENT_NIVEAU_UN (OID) values (?)
It seems that it considered Segmentation
as an ElementNiveauUn
but because of ENU_ELEMENT_NIVEAU_UN
is not-null="true"
within the ElementNiveauUn
mapping it's expecting to set the value which I already did but it's seems lost during the insertion process
Here's a simplified UML class diagram : http://goo.gl/vOHHC
精彩评论