您的位置:首页 > 数据库

SQL,HQL查询方式写法

2012-09-06 19:58 351 查看
public List<RoleConfiguration> getRoleConfigurationsByOrganizationsAndSql(List<Organizations> organizations){
List<RoleConfiguration> 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<RoleConfiguration> getRoleConfigurationsByOrganizationsAndHql(List<Organizations> organizations){
List<RoleConfiguration> 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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐