Bonjour,
Je désire effectué une requête sur deux tables qui ont une relation many-to-many avec un critère de selection sur chaque table. le mapping des tables est le suivant:
Team.hbm.xml:
Season.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 <?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="com.yannick.lombard.gwt.client.model.Team" table="TEAMS"> <id name="id" type="int" column="ID"> <generator class="increment"/> </id> <property name="teamName" type="string"> <column name="TEAM_NAME" not-null="true" /> </property> <property name="teamTown" type="string"> <column name="TEAM_TOWN" not-null="true" /> </property> <property name="teamAbbrev" type="string"> <column name="TEAM_ABBREV" not-null="true" /> </property> <property name="teamStadiumName" type="string"> <column name="TEAM_STADIUM_NAME" not-null="true" /> </property> <property name="teamFoundationYear" type="string"> <column name="TEAM_FOUNDATION_YEAR" not-null="false" /> </property> <many-to-one name="country" column="country_id" not-null="false" class="com.yannick.lombard.gwt.client.model.Country" /> <set name="seasons" table="teams_seasons" lazy="false"> <key column="team_id"/> <many-to-many class="com.yannick.lombard.gwt.client.model.Season" column="season_id"/> </set> </class> </hibernate-mapping>
Country.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 <?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="com.client.model.Season" table="SEASONS" lazy="false"> <id name="id" type="int" column="ID"> <generator class="increment"/> </id> <property name="seasonYear" type="string"> <column name="SEASON_YEAR" not-null="true" /> </property> <set name="teams" table="teams_seasons" lazy="false"> <key column="season_id"/> <many-to-many class="com.yannick.lombard.gwt.client.model.Team" column="team_id"/> </set> </class> </hibernate-mapping>
Je désire récupérer toute les teams avec un country_id et un season_id.
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"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class name="com.client.model.Country" table="COUNTRIES" lazy="false"> <id name="id" type="int" column="ID"> <generator class="increment"/> </id> <property name="countryName" type="string"> <column name="COUNTRY_NAME" not-null="true" /> </property> <property name="countryAbbrev" type="string"> <column name="COUNTRY_ABBREV" not-null="true" /> </property> </class> </hibernate-mapping>
J'ai mis une image de la base en pièce jointes.
Partager