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?