-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Fetch join problem or hibernate fetch limitation?
PostPosted: Tue Oct 24, 2006 4:55 pm 
Newbie

Joined: Tue Oct 24, 2006 4:40 pm
Posts: 3
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


Top
 Profile  
 
 Post subject: solved
PostPosted: Wed Oct 25, 2006 3:32 am 
Newbie

Joined: Tue Oct 24, 2006 4:40 pm
Posts: 3
solved by using this function



public List<Country> fetchCountryDescriptions() {
return new ArrayList<Country>(new HashSet<Country>(
(ArrayList<Country>) getSession().createQuery(
"from Country c left join fetch c.countryDescriptions")
.list()));
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.