I Nico
I'm french so may be my english is not perfect; However, i'm trying to expose you my Problem.
First let me present you one of the part of my Database.
There are two main tables which are a primary key:
TTACHE_EXT
ID_TACHE Varchar(20) PK
NOMFIC VARCHAR(50)
The first one
TANNUAIRISTE
ID_ANNUAIRISTE Varchar(20) PK
NOM VARCHAR(50)
The second one
TTACHE_ANNU
ID_TACHE FK
ID_ANNUAIRISTE FK
DATE_BEGIN_TACHE DATE
DATE_END_TACHE DATE
is the relation table
To describe this model, i declare two files
one to represent TANNUAIRISTE and an another
to TTACHE, which contains the definition of the
set collection
See the date of this two file
in client.hbm.xml
<class name="Client" table="TANNUAIRISTE">
<id name="id" column="ID_ANNUAIRISTE">
<property name="nom" column="NOM">
...
</Class>
in tache.hbm.xml
<class name="Tache" table="TTache">
<id name="id" column="ID_TACHE">
<property name="nom" column="NOM">
...
<SET name="tacheClients" >
<INDEX column="ID_TACHE">
<composite-element class="TacheClient">
<many-to-one name="client" class="CLIENT" column="ID_ANNUAIRISTE">
<property name="dateDebut" column="DATE_BEGIN_TACHE">
<property name="dateFin" column="DATE_END_TACHE">
</composite-element>
</SET>
</class>
the depend class looks like it:
public class Tache {
private Set tacheClients;
+the getters/setters
public addTacheClient( Client _client, Date _dateDebut, Date _dateFin) {
TacheClient myTacheClient = new TacheClient();
myTacheClient.setDateDebut(_dateDebut);
myTacheClient.setDateFin(_dateFin);
myTacheClient.setClient(_client);
this.tacheClient.add(myTacheClient);
} //end of the method
}//end of the class
public class TacheClient implements Serializable {
private Client client;
private date datedebut;
private date datefin;
+the getters/setters and method equals/hashcode
}
I'm trying to create a new record in the table tache and many in the relation table TTACHE_ANNU
Tache myTache = new TACHE();
myTache.setNom("Toto");
...
myTache.addTacheClient( myClientXX, dateXX, dateYY);
I load a session so that i can register my New Tache and i hoped
a record in the relation table
I do ths code:
Transaction tx = session.beginTransaction();
session.save(myTache);
tx commit;
In fact, my New tache is registered but not my Elemnt in the collection..
I dont understand why not..therefore, i have no error neither warning
I will happy if someone can help me
Thanks
[/i]
|