-->
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.  [ 5 posts ] 
Author Message
 Post subject: The query generated by refresh method
PostPosted: Thu May 18, 2006 10:00 am 
Newbie

Joined: Wed Oct 26, 2005 3:37 am
Posts: 15
Hello!

I am using JBoss 4.0.4 RC2 with corresponding built-in implementation.

I came across the following weird (at least for me) situation:
I have an entity with a few collection properties such as:


@Entity
@Table(name = "t_Site")
public class Site {

@OneToMany(mappedBy = "site", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@OrderBy(value="day")
public List<SiteScheduleDay> getSchedule() {
return schedule;
}


@OneToMany(mappedBy = "site", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@OrderBy(value="dateStart")
public List<SiteZone> getZones() {
return zones;
}

}

At some point in my application these collections are fetched. After this I call EntityManager.refresh and the generated query is:

select site0_.id as id25_2_,
site0_.name_bg as name2_25_2_,
site0_.name_en as name3_25_2_,
site0_.type_id as type8_25_2_,
site0_.phonecode as phonecode25_2_,
site0_.municipality_id as municipa9_25_2_,
site0_.hasschedule as hassched5_25_2_,
site0_.postcode as postcode25_2_,
site0_.eknm as eknm25_2_,
zones1_.site_id as site4_4_,
zones1_.id as id4_,
zones1_.id as id28_0_,
zones1_.zone_id as zone3_28_0_,
zones1_.datestart as datestart28_0_,
zones1_.site_id as site4_28_0_,
schedule2_.site_id as site6_5_,
schedule2_.id as id5_,
schedule2_.id as id26_1_,
schedule2_.day as day26_1_,
schedule2_.site_id as site6_26_1_,
schedule2_.hourstart as hourstart26_1_,
schedule2_.hourend as hourend26_1_,
schedule2_.hourendorders as hourendo5_26_1_
from t_Site site0_, mm_Site_Zone zones1_, t_Site_Schedule schedule2_
where site0_.id = zones1_.site_id(+)
and site0_.id = schedule2_.site_id(+)
and site0_.id = ?
order by zones1_.datestart asc, day asc

If I have 1 SiteZone and 2 SiteScheduleDays for a Site, 2 records are returned by the query above and site.getSchedule() has 2 elements while site.getZones() has also 2 (they are the same).

Is this the proper behaviour or a bug? Am I missing something basic here?

Any help is highly appreciated!

Jana Parvanova


Top
 Profile  
 
 Post subject: loading objects
PostPosted: Fri May 19, 2006 3:41 am 
Newbie

Joined: Wed Oct 26, 2005 3:37 am
Posts: 15
Ok, I guess the problem is not with query but in the collections building from the result set.
So far I changed the collections' types to Set so that all elements are unique but the problem with Lists is still there.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 19, 2006 4:31 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
From Hibernate documentation:
Quote:
Note that queries that make use of eager fetching of collections usually return duplicates of the root objects (but with their collections initialized). You can filter these duplicates simply through a Set.


And explanation from JIRA issue:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-1513

Rgds, Ales


Top
 Profile  
 
 Post subject: thanks
PostPosted: Fri May 19, 2006 4:39 am 
Newbie

Joined: Wed Oct 26, 2005 3:37 am
Posts: 15
Ah, have missed these notes. Thank you, Sets then they will be...


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 19, 2006 4:50 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
Or look at Criteria's ResultTransformers.

Code:
public class DistinctRootEntityResultTransformer implements ResultTransformer {


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.