I work with Hibernate 4.3, using hmb.xml files and I need to access existing Oracle database.
Tables exemple :
Dossier :
id_dossier(int),
noDossier(int),
... ,
D_Crea(Date),
U_Crea(Varchar),
D_Maj(Date),
U_Maj(Varchar);
Adresse :
id_adresse(int),
rue(varchar),
...,
D_Crea(Date),
U_Crea(Varchar),
D_Maj(Date),
U_Maj(Varchar);
Contrat :
id_contrat(int),
d_signature(date),
...,
D_Crea(Date),
U_Crea(Varchar),
D_Maj(Date),
U_Maj(Varchar);
I can't change any thing on the DB structure.
POJOs :
abstract class CUObject{
private int id;
private Date createDate, updateDate;
private String createUser, updateUser;
}
class Dossier extends CUObject{
private String noDossier;
}
class Adresse extends CUObject{
private String rue;
}
class Contrat extends CUObject{
private Date signatureDate;
}
Changes on POJO's structure are possible.
Afert reading Hibernate documentation, the best way to map this hierrarchy seems to be using class and union-subclass :
<class abstract="true" name="CUObject">
<id />
<property column="D_CREA" name="createDate"/>
<property column="D_MAJ" name="updateDate"/>
<property column="U_CREA" name="createDate"/>
<property column="U_MAJ" name="updateUser"/>
<union-subclass name="Dossier" table="DOSSIER" >
<property column="NO_DOSSIER" name="numDossier" />
</union-subclass>
<union-subclass name="Addresse" table="ADRESSE" >
<property column="RUE" name="rue" />
</union-subclass>
<union-subclass name="Contrat" table="CONTRAT" >
<property column="D_SIGNATURE" name="signatureDate" />
</union-subclass>
</class>
But, like mentioned in documentation, "the column name must be the same on all subclass tables. The identity generator strategy is not allowed in union subclass inheritance. The primary key seed has to be shared across all unioned subclasses of a hierarchy."
This is a problem for me : I need a generator strategy for each subclass (oracle sequence), the primary key is not shared between subclasses, and the primary key has not same name across all subclasses.
What other approach to map CU fields without making horrible copy / paste on the mapping of each class?
Tanks a lot. PS : I use this site for several years now. I want to thank you for all the answers you've given me so far.