Bonjour à tous,
J'ai 2 tables: 'USER' et 'USERTITLE'
La table USERTITLE contient 4 colonnes dont: TITLEID(clé primaire) et TITLE
La table user contient plusieurs colonnes dont: ID(clé primaire), TITLE(clé étrangère référencée à la clé primaire de USERTITLE), NAME et SURNAME.
J'ai 2 objets 'UserTitle' et 'User' et 'UserTitle' est déclaré en tant que propriété de 'User'. Ce que je veux faire c'est d'avoir une requête de ce type.
avec le code suivant
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 select u.id as id, t.title as title, u.name as name, u.surname as surname from users u inner join usertitle t on u.title = t.titleid order by u.id
user.hbm.xml
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9 HibernateCallback callback = new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { Criteria criteria = session.createCriteria(User.class); return criteria.list(); } }; return getHibernateTemplate().executeFind(callback);
usertitle.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
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79 <?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 default-lazy="false"> <class name="org.deep.spring.mvc.user.User" table="users"> <id column="id" name="id" type="int"> <generator class="sequence"> <param name="sequence">seq_id_users</param> </generator> </id> <property name="civility"> <column name="title" /> </property> <property name="name"> <column name="name" /> </property> <property name="surname"> <column name="surname" /> </property> <property name="middleName"> <column name="middlename" /> </property> <property name="role"> <column name="role" /> </property> <property name="streetno"> <column name="street_no" /> </property> <property name="address"> <column name="address" /> </property> <property name="address2"> <column name="address2" /> </property> <property name="zip"> <column name="zip" /> </property> <property name="tel"> <column name="telephone" /> </property> <property name="tel2"> <column name="telephone2" /> </property> <property name="fax"> <column name="fax" /> </property> <property name="email"> <column name="email" /> </property> <property name="user"> <column name="username" /> </property> <property name="password"> <column name="password" /> </property> <property name="password2"> <column name="password2" /> </property> <property name="maidenName"> <column name="maiden_name" /> </property> <property name="city"> <column name="city" /> </property> <property name="state"> <column name="state" /> </property> <property name="country"> <column name="country" /> </property> <property name="officeDepart"> <column name="department" /> </property> <!-- 'name' is the name of the property declared in the bean User column is the name of the column in the table 'USERS'--> <many-to-one name="userTitle" column="TITLE" not-null="true" insert="false" update="false" /> </class> </hibernate-mapping>
la requete fonctionne, le inner join se passe bien mais j'obtiens une requete qui me selectionne toutes les données de la table et toutes les données de celle de usertitle,
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
19
20
21 <?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 default-lazy="false"> <class name="org.deep.spring.mvc.user.UserTitle" table="usertitle"> <id column="titleid" name="titleid" type="int"> <generator class="sequence"> <param name="sequence">SEQ_ID_USERTITLE</param> </generator> </id> <property name="languageId"> <column name="languageid" /> </property> <property name="language"> <column name="language" /> </property> <property name="title"> <column name="title" /> </property> </class> </hibernate-mapping>
Comment doivent être les fichiers mapping 'usertitle.hbm.xml' et 'user.hbm.xml' pour
Partager