I am having a table structure similar to this.
User
- UserId
- Name
- Other Attributes
UserAddresses
- AddressId
- UserId
- StreetName
- Other Attributes
Criteria myUserCrit = mySession.createCriteria(User.class)
.createAlias("userAddresses", "userAdd")
.add(Expression.eq("UserId", 1))
.add(Expression.eq("userAdd.StreetName", "XYZ"));
List userList = myUserCrit.list();
Here the first query shown in log is correct. i.e.
Select
------
From
User
join conditions with UserAddresses using userId
Where
userId condition AND
StreetName condition.
BUT
Second query is
Select
-------
from
UserAddress
Where
userId condition Only.
The second condition is not included because of which it returns me un wanted data. Hibernate mapping file for user contains userAddresses Set containing UserAddress objects.
Please suggest.
|