Hello everyone..! I'm new to Hibernate.
I've some queries in constructing Criteria instance with the following conditions.
I've 3 tables.
1. APPLICATION (APPLICATION_ID, NAME, CODE);
2. TOKEN ( TOKEN_ID, NAME, COMMENTS, APPLICATION_ID);
3. TOKENUSER( TOKEN_ID (integer), USER_ID(varchar));
I need to construct a criteria instance for the below query.
SELECT A.TOKENID TOKENID, A.COMMENTS
COMMENTS, A.NAME TOKENNAME, C.CODE CODE
FROM TOKEN A, TOKENUSER B, APPLICATION C
WHERE
A.APPLICATION_ID = C.APPLICATION_ID
AND A.TOKEN_ID =B.TOKEN_ID
AND LOWER(B.USER_NAME) = 'jack' AND
LOWER(C.CODE) = 'mars';
Criteria Object:
-------------------
Criteria criteria = session.createCriteria(CsApplication.
List list = criteria.add( Restrictions.eq("applicationCode", "mars")).list();
I've created POJOs & .hbm files for APPLICATION & TOKEN tables. TOKEN_USER table acts a place holder of many to many relation between the tokens and the user name.
My question is as I dont have a separate table/Java Object for USER entity,
is it possible to weave the association between TOKEN & TOKEN_USER tables? And how to add the condition in criteria object for (B.USER_NAME = 'jack') ?
Your help will be highly appreciated.
Thanks,
Velmurugan22k.
|