SQL,HQL查询方式写法

public List getRoleConfigurationsByOrganizationsAndSql(List organizations){

List roleList = null;

// select * from roleconfiguration r where r.`OrganizationId` in (1,2)

String sql =  "select * from roleconfiguration r where r.OrganizationId in (";

for (Organizations org : organizations) {

sql += org.getId()+",";

} // select * from roleconfiguration r where r.`OrganizationId` in (1,2,

if(sql.endsWith(",")){

sql = sql.substring(0, sql.length() -1); // select * from roleconfiguration r where r.`OrganizationId` in (1,2

}

sql += ")"; //// select * from roleconfiguration r where r.`OrganizationId` in (1,2)

roleList = this.findBySql(sql);

return roleList;

}

public List getRoleConfigurationsByOrganizationsAndHql(List organizations){

List roleList = null;

String hql = " select r from RoleConfiguration r where r.organizations.id in (";

for (Organizations org : organizations) {

hql += org.getId()+",";

}

if(hql.endsWith(",")){

hql = hql.substring(0, hql.length()-1);

}

hql += ")";

roleList = this.executeQueryByHQL(hql, null);

return roleList;

}

你可能感兴趣的:(SQL)