Hi, I am trying to generate the following SQL in hibernate using the HibernateTemplate:
Code:
SELECT TRAN_CLNT_GRP.GRP_NAME AS GRP_NAME
FROM TRAN_CLNT_GRP
JOIN TRAN_USER_GRP
ON TRAN_CLNT_GRP.GRP_ID_SGN = TRAN_USER_GRP.GRP_ID
JOIN TRAN_CLNT
ON TRAN_CLNT.CLNT_ID_SGN = TRAN_USER_GRP.CLNT_ID
WHERE TRAN_USER_GRP.USER_ID = 'foobar'
AND TRAN_CLNT.CLNT_NAME = 'Internal Client'
This is the method I wrote using a DetachedCriteria....
Code:
public List<String> fetchSecAdminGroupByUserId(final String userID) {
final DetachedCriteria criteria = DetachedCriteria
.forClass(TranClntGrp.class);
criteria.createCriteria("tranClnt");
criteria.createCriteria("tranUserGrp");
criteria.setProjection(Projections
.projectionList()
.add(Projections.property("tranClntGrp.grpName").as("grpName")));
criteria.add(Restrictions.eq("tranUserGrp.comp_id.userId", userID));
criteria.add(Restrictions.eq("tranClnt.clntName", "Agilink Internal Client"));
final List<String> results = (List) get(criteria);
return results;
}
These are the tables value objects :
Code:
public class TranUserGrp implements Serializable {
private dao.hibernate.vo.TranUserGrpPK comp_id;
..................}
Code:
public class TranUserGrpPK implements Serializable {
private Long clntId;
private String userId;
private Long grpId;
..............}
Code:
public class TranClntGrp implements Serializable {
private dao.hibernate.vo.TranClntGrpPK comp_id;
private String grpName;
...................}
Code:
public class TranClnt implements Serializable {
private Long clntIdSgn;
private String clntName;
......................}
When I ran my method it is throwing this exception:
org.hibernate.QueryException: could not resolve property: tranUserGrp of: .dao.hibernate.vo.TranClntGrpCan you please tell me what I am doing wrong? Thanks.