this is the generated SQL from Hibernate:
Code:
SELECT
tbb.BILLINGKEY as BILLINGKEY9_0_,
tbb.SITEKEY as SITEKEY9_0_,
tbb.SALESNUMBER as SALESNUM3_9_0_,
tbb.LOGIN as LOGIN9_0_,
tbb.EMPLOYEETYPECODE as EMPLOYEE5_9_0_,
tbb.EMPLOYEENUMBER as EMPLOYEE6_9_0_,
tbb.PURGED_IND as PURGED7_9_0_,
tbb.PROCESS_FLG as PROCESS8_9_0_,
tbb.CREATEDT as CREATEDT9_0_,
tbb.LASTUPDATEDT as LASTUPD10_9_0_,
tmus.USERSUPERVISORKEY as USERSUPE1_14_1_,
tmus.USERKEY as USERKEY14_1_,
tmus.SUPERVISORKEY as SUPERVIS3_14_1_,
tmus.CREATEDT as CREATEDT14_1_,
tmus.EFFECTIVESTARTDATE as EFFECTIV5_14_1_,
tmus.EFFECTIVEENDDATE as EFFECTIV6_14_1_,
tmus.CURRENTFLG as CURRENTFLG14_1_,
dt.DISAPPROVAL_TYPE_ID as DISAPPRO1_3_2_,
dt.DESCRIPTION as DESCRIPT2_3_2_,
s.SITE_ID as SITE1_8_3_,
s.NAME as NAME8_3_,
s.CODE as CODE8_3_,
ia.AUDIT_ID as AUDIT1_5_4_,
ia.START_DATE as START2_5_4_,
ia.DESCRIPTION as DESCRIPT3_5_4_,
ia.SITE_ID as SITE5_5_4_,
ia.END_DATE as END4_5_4_,
ast.AUDIT_STATUS_ID as AUDIT1_2_5_,
ast.DESCRIPTION as DESCRIPT2_2_5_
FROM
Employee e,
Tbuser tbu,
Tmuserbilling tmub,
Tbbilling tbb,
Audit_Status ast,
Tmusersupervisor tmus,
Note n,
Activity a,
Icoms_Audit ia,
Disapproval_Type dt,
Site s
WHERE
e.idm_user_id = tbu.userkey
AND e.audit_status_id = ast.audit_status_id
AND e.audit_id = ia.audit_id
AND tbu.userkey = tmub.userkey
AND tmub.billingkey = tbb.billingkey
AND tbu.userkey = tmus.userkey
AND e.employee_id = a.employee_id
AND a.activity_id = n.activity_id
AND dt.disapproval_type_id = n.disapproval_type_id
AND s.site_id = ia.site_id
AND ast.audit_status_id in (
3, 4
)
based on this method:
Code:
public List searchAuditedUsers(String selectedSite, String selectedAudit, String icomsUser, String disapprovalType, String supervisorLastName, Boolean init){
log.info("begin searchAuditedUsers");
log.info("searchAuditedUsers(): selectedSite = " + selectedSite);
log.info("searchAuditedUsers(): selectedAudit = " + selectedAudit);
log.info("searchAuditedUsers(): icomsUser = " + icomsUser);
log.info("searchAuditedUsers(): disapprovalType = " + disapprovalType);
log.info("searchAuditedUsers(): supervisorLastName = " + supervisorLastName);
log.info("searchAuditedUsers(): init = " + init);
List list;
int ctr = 0;
StringBuffer query = new StringBuffer("SELECT {tbb.*}," +
" {tmus.*}," +
" {dt.*}, " +
" {s.*}, " +
" {ia.*}, " +
" {ast.*} "+
"FROM Employee e, "+
"Tbuser tbu, "+
"Tmuserbilling tmub, "+
"Tbbilling tbb, "+
"Audit_Status ast, "+
"Tmusersupervisor tmus, "+
"Note n, "+
"Activity a, "+
"Icoms_Audit ia, "+
"Disapproval_Type dt, "+
"Site s "+
"WHERE e.idm_user_id = tbu.userkey "+
"AND e.audit_status_id = ast.audit_status_id "+
"AND e.audit_id = ia.audit_id "+
"AND tbu.userkey = tmub.userkey "+
"AND tmub.billingkey = tbb.billingkey "+
"AND tbu.userkey = tmus.userkey "+
"AND e.employee_id = a.employee_id "+
"AND a.activity_id = n.activity_id "+
"AND dt.disapproval_type_id = n.disapproval_type_id "+
"AND s.site_id = ia.site_id");
//add appenders
if (init != null && init == true) {
query.append(" AND ast.audit_status_id in (3, 4)"); //if report is access the first time in session, result set should be filtered for disapproved and disapproved in process
}
if (selectedSite != null && selectedSite.trim().length() > 0) {
query.append(" AND ia.site_id = ? ");
}
if (selectedAudit != null && selectedAudit.trim().length() > 0) {
query.append(" AND ia.audit_id = ?");
}
if (icomsUser != null && icomsUser.trim().length() > 0) {
query.append(" AND LOWER(tbb.login) like LOWER(?) ");
}
if (disapprovalType != null && disapprovalType.trim().length() > 0) {
query.append(" AND n.disapproval_type_id = ?");
}
if (supervisorLastName != null && supervisorLastName.trim().length() > 0) {
query.append(" AND tmus.supervisorkey in (SELECT tbu.userkey FROM Tbuser tbu WHERE LOWER(tbu.lastname) like LOWER(?))");
}
Session session = (Session) entityManager.getDelegate();
SQLQuery q = session.createSQLQuery(query.toString())
.addEntity("tbb", Tbbilling.class)
.addEntity("tmus", Tmusersupervisor.class)
.addEntity("dt", DisapprovalType.class)
.addEntity("s", Site.class)
.addEntity("ia", IcomsAudit.class)
.addEntity("ast", AuditStatus.class);
//set params
if (selectedSite != null && selectedSite.trim().length() > 0) {
q.setParameter(ctr++, Integer.parseInt(selectedSite.trim()));
}
if (selectedAudit != null && selectedAudit.trim().length() > 0) {
q.setParameter(ctr++, Integer.parseInt(selectedAudit.trim()));
}
if (icomsUser != null && icomsUser.trim().length() > 0) {
q.setParameter(ctr++, "%"+icomsUser.trim()+"%");
}
if (disapprovalType != null && disapprovalType.trim().length() > 0) {
q.setParameter(ctr++, Integer.parseInt(disapprovalType.trim()));
}
if (supervisorLastName != null && supervisorLastName.trim().length() > 0) {
q.setParameter(ctr++, "%"+supervisorLastName.trim()+"%");
}
list = q.list();
return list;
}