J'aimerais savoir si ce mapping est correct parce que j'ai des erreurs par la suite.
2 tables (ds ma bdd):
Tabless Champs
----------- ----------
idTable int idChamp int
nomTable String nomChamp String
idTable int
Donc plusieurs champs possible pour une table mais un champs n'appartient qu'à une seule table.
Tabless.hbm.xml :
Champs.hbm.xml :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="commun.Dao"> <class name="Tabless" table="tabless" optimistic-lock="none"> <id name="idTable" type="integer" unsaved-value="null"> <column name="idTable" not-null="true" unique="true" index="PRIMARY"/> <generator class="native"/> </id> <property name="nomTable" type="string" column="nomTable" length="25" not-null="true"/> <property name="idBdd" type="integer" column="idBdd"/> <set name="champs" inverse="true" cascade="all-delete-orphan" > <key column="table"/> <one-to-many class="Champs" /> </set> </class> </hibernate-mapping>
Les fichiers java :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="commun.Dao"> <class name="Champs" table="champs" optimistic-lock="none"> <id name="idChamp" type="integer" unsaved-value="null"> <column name="idChamp" not-null="true" unique="true" index="PRIMARY"/> <generator class="native"/> </id> <property name="nomChamp" type="string" column="nomChamp" length="25" not-null="true"/> <many-to-one name="table" class="Tabless" not-null="true" /> </class> </hibernate-mapping>
Tabless.java
// attributs
private int idTable;
private String nomTable;
// associations
private Set champs;
Champs.java
// attributs
private int idChamp;
private String nomChamp;
// associations
private Table table;
Je ne mets pas les accesseurs.
est-ce correct ?
merci pour vos réponses.
Partager