I'm making a criteria object, but one of the criteria is complicated. I want to make one of the criterion "last name", but the table doesn't have a last name. It does have a foreign key ID to the table that does. So I'd like to insert some sql into the criterion, but I can't find an example of this. It also needs to allow other "normal" criterion into the criteria (example: criteria.add( Restrictions.ilike( "activity_type", activityTypeId, MatchMode.EXACT ) ); )
Here's the sample SQL of what I was planning:
FROM account, user
WHERE account.user_id = user.user_id
AND user.last_name like :variable
Just create an instance of the associated object and initialize the name property and add it to the criteria query. Don't try mixing the HQL and criteria. That will over-complicate things greatly.
Your criteria doesn't all have to go to one table.
posted 7 years ago
The account object doesn't hold onto any instances of user (i.e., there's no "list of users" in an account object - they're separate entities with no relation as far as the app's concerned), so I don't think your solution would work.
money grubbing section goes here:
the new thread boost feature: great for the advertiser and smooth for the coderanch user