Hibernate version:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.2.0.cr2</version>
</dependency>
PersistentBean + annotations:
--------------------------------------- Country ---------------------------
@Entity
@Table(name = "COUNTRY")
public class Country extends PersistentBean{
private List<CountryDescription> countryDescriptions;
@OneToMany(mappedBy="country", fetch = FetchType.LAZY)
public List<CountryDescription> getCountryDescriptions() {
return countryDescriptions;
}
public void setCountryDescriptions(List<CountryDescription> countryDescriptions) {
this.countryDescriptions = countryDescriptions;
}
....
}
------------------------------------------------------- Country Description ----
@Entity
@Table(name="COUNTRYDESCRIPTION")
public class CountryDescription extends PersistentBean{
private Country country;
@ManyToOne(optional=false, fetch=FetchType.LAZY)
public Country getCountry() {
return country;
}
public void setCountry(Country country) {
this.country = country;
}
...
}
code
ArrayList<Country> lst = (ArrayList<Country>) getSession().createCriteria(Country.class).setFetchMode("countryDescriptions", FetchMode.JOIN).list();
expected result
- the country table has 7 records each country has 3 country descriptions
- I expect to have an arrayList with 7 country records with each an ArrayList of 3 countryDescriptions
result
- An ArrayList of 21 country with each one country description
generated SQL
select this_.id as id3_1_,
this_.cdate as cdate3_1_,
this_.lockindicator as lockindi3_3_1_,
this_.udate as udate3_1_,
this_.uuser as uuser3_1_,
this_.cuser as cuser3_1_,
this_.code as code3_1_,
countrydes2_.country_id as country9_3_,
countrydes2_.id as id3_,
countrydes2_.id as id4_0_,
countrydes2_.cdate as cdate4_0_,
countrydes2_.lockindicator as lockindi3_4_0_,
countrydes2_.udate as udate4_0_,
countrydes2_.uuser as uuser4_0_,
countrydes2_.cuser as cuser4_0_,
countrydes2_.name as name4_0_,
countrydes2_.country_id as country9_4_0_,
countrydes2_.languageCode as language8_4_0_
from COUNTRY this_
left outer join COUNTRYDESCRIPTION countrydes2_ on this_.id=countrydes2_.country_id
Some help would be great,
Pieter
|