-->
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.  [ 1 post ] 
Author Message
 Post subject: Criteria result set compared to generated SQL result set...
PostPosted: Fri Jun 25, 2010 10:31 am 
Newbie

Joined: Fri Jun 25, 2010 9:23 am
Posts: 2
Hi.

I'm using Criteria API to dynamically build query on Alert, User and UserReceivedAlert classes which are in many-to-many relationship. Relationship is modeled with 2 one-to-many many-to-one pairs. Here is the code for criteria :
Code:
Criteria ura = session.createCriteria(UserReceivedAlert.class);
Criteria alert = ura.createCriteria("alert");
Criteria user = ura.createCriteria("user");

user.add(Restrictions.like("username", "somename"));
ura.list();

When I run the generated sql separately from hibernate, result set contains exactly what I need. For my scenario it's 6 rows. Criteria returns list of only 2 items and it's in some sort of aggregated form. I need to be able to get exactly the same result set from criteria as I would from sql.
Not applying the restriction however, returns the same number of rows as sql does.
Code:
select
        this_.id as id4_3_,
        this_.dateDeletedByAgent as dateDele2_4_3_,
        this_.dateRead as dateRead4_3_,
        this_.dateDeletedByUser as dateDele4_4_3_,
        this_.userReply as userReply4_3_,
        this_.alertID as alertID4_3_,
        this_.recipientID as recipien6_4_3_,
        alert3_.id as id2_0_,
        alert3_.senderID as senderID2_0_,
        alert3_.subject as subject2_0_,
        alert3_.description as descript3_2_0_,
        alert3_.content as content2_0_,
        alert3_.requiresUserConfirmation as requires5_2_0_,
        alert3_.priority as priority2_0_,
        alert3_.deliveryType as delivery7_2_0_,
        alert3_.dateSent as dateSent2_0_,
        user1_.id as id3_2_,
        user1_.username as username3_2_,
        user1_.password as password3_2_,
        user1_.isConsumer as isConsumer3_2_,
        user1_.msisdn as msisdn3_2_,
        user1_.email as email3_2_
    from
        userReceivedAlerts this_
    left outer join
        alerts alert3_
            on this_.alertID=alert3_.id
    inner join
        users user1_
            on this_.recipientID=user1_.id
    where
        user1_.username like ?

Hibernate 3.2.4 SP1, Oracle 10g

Any suggestions?


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

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.