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;
}
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;
}
相关文章推荐
- Hibernate 的三种查询方式:HQL、Criteria、Sql
- Hibernate 的三种查询方式:HQL、Criteria、Sql
- Hibernate的四种查询方式(主键查询,HQL查询,Criteria查询,本地sql查询)和修改和添加
- Hibernate的四种查询方式(主键查询,HQL查询,Criteria查询,本地sql查询)和修改和添加
- Hibernate 检索查询的几种方式(HQL,QBC,本地SQL,集成Spring等)
- Hibernate 的三种查询方式:HQL、Criteria、Sql
- Hibernate 的三种查询方式:HQL、Criteria、Sql
- Hibernate 检索查询的几种方式(HQL,QBC,本地SQL,集成Spring等)
- hql与sql不同的查询方式
- Hibernate 的三种查询方式:HQL、Criteria、Sql
- Hibernate 检索查询的几种方式(HQL,QBC,本地SQL,集成Spring等)
- Hibernate查询之SQL查询,查询结果用new新对象的方式接受,hql查询,通过SQL查询的结果返回到一个实体中,查询不同表中内容,并将查到的不同表中的内容放到List中
- hibernate查询方式:HQL、SQL、Criteria方法、命名、动态分离查询、例子查询
- Hibernate的HQL查询及原生sql查询语句写法
- Hibernate查询之SQL查询,查询结果用new新对象的方式接受,hql查询,通过SQL查询的结果返回到一个实体中,查询不同表中内容,并将查到的不同表中的内容放到List中
- Spring data jpa HQL @Query 自定义查询及更新删除 及 sql写法
- Hibernate 的三种查询方式:HQL、Criteria、Sql
- hibernate查询方式:HQL、SQL、Criteria方法、命名、动态分离查询、例子查询
- Hibernate 的三种查询方式:HQL、Criteria、Sql
- Hibernate学习-07:CRUD(增删改查)操作之查询多条/所有记录HQL、QBC、SQL三种方式