J'ai crée mon fichier de mapping pour une table mais je ne sais pas ou le placer dans l'arborescence du projet?
merci
Note: je travaille sous netbeans
Version imprimable
J'ai crée mon fichier de mapping pour une table mais je ne sais pas ou le placer dans l'arborescence du projet?
merci
Note: je travaille sous netbeans
La convention c'est de le mettre au même endroit que la classe (le .java) correspondant
J'ai appelé mon fichier Student.hbm.xml et je l'ai placé au meme endroit qu'hibernate dans src.
voici son contenu :
Sachant que j'ai une classe Student qui se trouve dans le package testhibernate et que la table associée se nomme STUDENT.Code:
1
2
3
4
5
6
7
8
9
10
11
12
13 <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class name="testhibernate.Student" table="STUDENT"> </class> </hibernate-mapping>
Pourtant le compilo me dit :
Donc ou est le probleme?Code:
1
2
3
4
5 14-Apr-2008 09:03:44 xdoclet.XDocletMain start INFO: Running <hibernate/> Generating mapping file for testhibernate.Student. testhibernate.Student
Je ne sais pas trop si ca peut venir de la, mais je spécifie le package dans mon fichier de mapping :
Code:
1
2
3
4
5
6
7
8
9
10 <hibernate-mapping package="org.esupportail.impact.domain.beans"> <class name="Intervention" table="imp_intervention"> <id name="id" column="id" type="int"> <generator class="native"/> </id> <property name="date_creation" column="date_creation" type="timestamp"/> </class> </hibernate-mapping>
ok mais la je suis dans le package par defaut.
Que dois je specifier alors ?
merci
En fait c'est dans le fichier de configuration Hibernate (généralement appelé hibernate.cfg.xml) que tu indique l'endroit où se trouve ton fichier de mapping (hbm.xml).
Si tu laisse ton fichier de mapping dans le répertoire "src" alors dans ton fichier de config, utilise :
Si tu le mets au même endroit que la classe testhibernate.Student utilise :Code:
1
2
3
4
5
6
7 <hibernate-configuration> <session-factory> (...) <mapping resource="Student.hbm.xml"/> </session-factory> </hibernate-configuration>
Et ça devrait fonctionnerCode:
1
2
3
4
5
6
7 <hibernate-configuration> <session-factory> (...) <mapping resource="testhibernate/Student.hbm.xml"/> </session-factory> </hibernate-configuration>