I need to refactor an existing application mappings. The trouble arises
with the hierarchy:
Movimento --> MovimentoIncasso
Movimento --> MovimentoCassa
Movimento --> MovimentoAttivo --> Fattura
in database there are 3 tables : one for MovimentoIncasso,
a table for MovimentoCassa and a table for MovimentoAttivo.
No tables for Fattura.
Movimento is an abstract class.
Each table has all the fields of the abstract root class Movimento.
At present MovimetoAttivo and Fattura are mapped
with one table per hierachy strategy.
While MovimentoIncasso and MovimentoCassa seems to be ok to
be mapped with union subclass, I can't do the same for MovimentoAttivo
and Fattura.
the reference at chapter 9 talks about defining different mapping in different files to change inheritance strategy for a subtree of a hierarchy.
Quote:
It is possible to define subclass, union-subclass, and joined-subclass mappings in separate mapping documents, directly beneath hibernate-mapping. This allows you to extend a class hierachy just by adding a new mapping file.
I missed something: I can't get to it.
With the following mappings there is no exception, but MovimentoIncasso
and MovimentoCassa seems to be mapped by Movimento and not by
MovimentoIncasso or MovimentoCassa. The Hibernate query referes to
MovimentoAttivoTestate table and not to the correct table.
If I set abstract=true on Movimento, MovimentoAttivo loses
the reference to the table.
Thanks in advance
m
Hibernate version: 3.2.1
Mapping documents:
Movimento.hbm.xml
Code:
<hibernate-mapping package="net.areait.fisco.gestionecia.core.model">
<class name="Movimento" table="MOVIMENTOATTIVOTESTATA">
<id name="id" column="ID">
<generator class="sequence">
<param name="sequence">MOVIMENTOTESTATASEQID</param>
</generator>
</id>
<discriminator formula="(SELECT decode(A.CODICE,'FAT','F','T') FROM CODICEMOVIMENTO C join TIPOMOVIMENTO A on A.ID = C.IDTIPOMOVIMENTO WHERE C.ID = IDCODICEMOVIMENTO)" />
<property name="segnoTotaleMovimento" column="SEGNO">
<type name="net.areait.fisco.gestionecia.core.model.UserTypeVO">
<param name="ClassNameVO">net.areait.fisco.gestionecia.core.model.Segno</param>
<param name="property">value</param>
</type>
</property>
<property name="statoContabile" column="FLGCONTABILIZZATO">
<type name="net.areait.fisco.gestionecia.core.model.UserTypeVO">
<param name="ClassNameVO">net.areait.fisco.gestionecia.core.model.StatoContabile</param>
<param name="property">value</param>
</type>
</property>
<property name="totaleMovimento" column="TOTALEMOVIMENTO" type="java.math.BigDecimal"/>
<property name="numero" column="NUMEROMOVIMENTO" />
<property name="anno" column="ANNOMOVIMENTO"/>
<property name="descrizione" column="DESCRIZIONE"/>
<property name="data" column="DATAMOVIMENTO"/>
<many-to-one name = "provincia"
column = "IDPROVINCIA"
class = "net.areait.fisco.core.model.anagrafica.Provincia"
lazy="false">
</many-to-one>
<many-to-one name = "codiceMovimento"
column = "IDCODICEMOVIMENTO"
class = "CodiceMovimento"
lazy="false">
</many-to-one>
<many-to-one name = "centroCosto"
column = "IDCENTRODICOSTO"
class = "CentroDiCosto"
lazy = "false">
</many-to-one>
<subclass name="MovimentoAttivo"
discriminator-value="T"
abstract="false"
proxy="MovimentoAttivo"
lazy="true"
extends="Movimento">
<many-to-one name = "associato"
column = "IDASSOCIATO"
class = "Associato"
lazy = "false">
</many-to-one>
<many-to-one name = "condizionePagamento"
column = "IDCONDIZIONIDIPAGAMENTO"
class = "CondizioniDiPagamento"
lazy = "false">
</many-to-one>
<property name="statoStampaDocumento" column="FLGSTAMPATO">
<type name="net.areait.fisco.gestionecia.core.model.UserTypeVO">
<param name="ClassNameVO">net.areait.fisco.gestionecia.core.model.StatoStampa</param>
<param name="property">value</param>
</type>
</property>
<set name="righeMovimento" table="MOVIMENTOATTIVORIGHE" lazy="false" inverse="false" cascade="all-delete-orphan">
<key column="IDTESTATA" not-null="true"/>
<one-to-many class="RigaMovimentoAttivo" />
</set>
<subclass name="Fattura"
discriminator-value="F"
abstract="false">
<property name="prefissoFattura">
<column name="PREFISSOFATTURA"/>
<type name="net.areait.fisco.gestionecia.core.model.UserTypeVO">
<param name="ClassNameVO">net.areait.fisco.gestionecia.core.model.PrefissoFattura</param>
<param name="property">prefissoFattura</param>
</type>
</property>
<property name="numeroFattura" column="NUMEROFATTURA"/>
<property name="dataFattura" column="DATAFATTURA"/>
</subclass>
</subclass>
</class>
</hibernate-mapping>
MovimentoCassa.hbm.xml
Code:
<hibernate-mapping>
<union-subclass name="net.areait.fisco.gestionecia.core.model.MovimentoCassa"
table="MOVIMENTOCASSATESTATA"
abstract="false"
extends="net.areait.fisco.gestionecia.core.model.Movimento">
<set name="righeMovimento" table="MOVIMENTOCASSARIGHE" lazy="false" inverse="false" cascade="all-delete-orphan">
<key column="IDTESTATA" not-null="true"/>
<one-to-many class="net.areait.fisco.gestionecia.core.model.RigaMovimentoCassa" />
</set>
</union-subclass>
</hibernate-mapping>
MovimentoIncasso.hbm.xml
Code:
<hibernate-mapping>
<union-subclass name="net.areait.fisco.gestionecia.core.model.MovimentoIncasso" table="MOVIMENTOINCASSOTESTATA"
abstract="false"
extends="net.areait.fisco.gestionecia.core.model.Movimento">
<many-to-one name = "associato"
column = "IDASSOCIATO"
class = "net.areait.fisco.gestionecia.core.model.Associato"
lazy = "false">
</many-to-one>
<set name="righeMovimento" table="MOVIMENTOINCASSORIGHE" lazy="false" inverse="false" cascade="all-delete-orphan">
<key column="IDTESTATA" not-null="true"/>
<one-to-many class="net.areait.fisco.gestionecia.core.model.RigaMovimentoIncasso" />
</set>
</union-subclass>
</hibernate-mapping>
Name and version of the database you are using: ORACLE 10.2.0.1.0