-->
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.  [ 3 posts ] 
Author Message
 Post subject: Counting an Extra Lazy Collection ignores @Where annotation
PostPosted: Wed Jul 23, 2008 12:25 pm 
Newbie

Joined: Mon Dec 17, 2007 6:59 pm
Posts: 3
Hibernate version: Hibernate 3.2.6, Hibernate Annotations 3.3.1, Hibernate Entity Manager 3.3.2

Structure: There are users. Users can duel each other. In a duel, the users are mapped as the challenger and the challengee. In the User bean, there are various collections of duels, such as receivedDuels (mapped by challengee) and initiatedDuels (mapped by challenger). There are scores associated with duels, mapped as challengerScore and challengeeScore. There are also collections of duels in the User bean that include @Where annotations to add conditions relating to the challengerScore or challengeeScore. The particular collection at issue is:

Code:
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "challenger")
    @LazyCollection(LazyCollectionOption.EXTRA)
    @Where(clause="challenger_score_id IS NOT NULL AND challengee_score_id IS NULL")
    private Collection<Duel> duelsAwaitingResponse;


I have the extra lazy collection option enabled because I frequently query the size() of this collection without ever using the elements, and thus want Hibernate to execute a COUNT query rather than load the collection. The @Where condition on this collection specifies that I only want duels where the challenger has played (and thus has a score) and the challengee has not played, and thus does not have a score.

However, when calling size() on my collection, the generated sql is simply:
Quote:
select count(duel_id) from duels where challenger_id =?


As you can see, the count statement generated because of the extra lazy collection ignores the @Where condition on the collection. The SQL generated if I actually load the collection is correct, but unfortunately calling size() on that collection returns the same as if the collection had not had the @Where annotation.

I have been unable to find any documentation indicating that this is the desired behavior, as well as any documentation addressing what should happen in this case. As such, I think it is implied that the @Where condition should apply to all queries generated for the collection, including COUNTs done by extra lazy loading.

Has anybody encountered this before? Does anybody know if this is the intended behavior? If so, can anybody explain why this is the intended behavior?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 24, 2008 12:26 pm 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

it seems logical to expect that the @Where clause is applied. Maybe you could create a jira issue and attach a test case?

--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 24, 2008 2:51 pm 
Newbie

Joined: Mon Dec 17, 2007 6:59 pm
Posts: 3
I wrote a blog post about this too, and somebody left a comment pointing me to http://opensource.atlassian.com/project ... e/HHH-3319 which demonstrates the issue as well.


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