1.java 实体对象
package com.helloworld.domain;
// Generated 2012-3-7 18:14:29 by Hibernate Tools 3.2.1.GA
/**
* TbAccount generated by hbm2java
* @author liuqing
*/
public class TbAccount implements java.io.Serializable {
private Integer id;
private TbPerson tbPerson;
private String name;
public TbAccount() {
}
public TbAccount(TbPerson tbPerson, String name) {
this.tbPerson = tbPerson;
this.name = name;
}
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
public TbPerson getTbPerson() {
return this.tbPerson;
}
public void setTbPerson(TbPerson tbPerson) {
this.tbPerson = tbPerson;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
}
2.实体对象
package com.helloworld.domain;
// Generated 2012-3-7 18:14:29 by Hibernate Tools 3.2.1.GA
/**
* TbJws generated by hbm2java
* @author liuqing
*/
public class TbJws implements java.io.Serializable {
private Integer id;
private TbPerson tbPerson;
private String jwsname;
public TbJws() {
}
public TbJws(TbPerson tbPerson, String jwsname) {
this.tbPerson = tbPerson;
this.jwsname = jwsname;
}
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
public TbPerson getTbPerson() {
return this.tbPerson;
}
public void setTbPerson(TbPerson tbPerson) {
this.tbPerson = tbPerson;
}
public String getJwsname() {
return this.jwsname;
}
public void setJwsname(String jwsname) {
this.jwsname = jwsname;
}
}
package com.helloworld.domain;
// Generated 2012-3-7 18:14:29 by Hibernate Tools 3.2.1.GA
import java.util.HashSet;
import java.util.Set;
/**
* TbPerson generated by hbm2java
* @author liuqing
*/
public class TbPerson implements java.io.Serializable {
private Integer id;
private String name;
private Set tbJwses = new HashSet(0);
private Set tbAccounts = new HashSet(0);
public TbPerson() {
}
public TbPerson(String name, Set tbJwses, Set tbAccounts) {
this.name = name;
this.tbJwses = tbJwses;
this.tbAccounts = tbAccounts;
}
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public Set getTbJwses() {
return this.tbJwses;
}
public void setTbJwses(Set tbJwses) {
this.tbJwses = tbJwses;
}
public Set getTbAccounts() {
return this.tbAccounts;
}
public void setTbAccounts(Set tbAccounts) {
this.tbAccounts = tbAccounts;
}
}
3. QBC 多表查询方法
public static void main(String args[]) {
Session session = new Configuration().configure().buildSessionFactory().openSession();
org.hibernate.Criteria criteria = session.createCriteria(TbPerson.class);
//对集合对象创建别名
criteria.createAlias("tbJwses", "a_jws");
criteria.add(org.hibernate.criterion.Restrictions.eq("a_jws.jwsname", "3"));
List list = criteria.list();
for (int i = 0 ; i < list.size(); i++) {
System.out.println("===" + ((TbPerson)list.get(i)).getName() + " id:" + ((TbPerson)list.get(i)).getId() );
}
}
4. HQL 语言的实现
List list = session.createQuery("SELECT p FROM TbPerson p inner join p.tbJwses j WHERE j.jwsname='3'").list();
for (int i = 0 ; i < list.size() ; i++) {
System.out.println(list.get(i).getClass());
}
分享到:
相关推荐
Hibernate_QBC查询
Hibernate(HQL、QBC查询)源码 Hibernate(HQL、QBC查询)源码 Hibernate(HQL、QBC查询)源码 Hibernate(HQL、QBC查询)源码 Hibernate(HQL、QBC查询)源码
Hibernate QBC高级查询 大家放心收藏! saivixky出品!必属精品!
QBC的各种查询,采用mvc多hibernate的封装,是很好的资料
收录了QBC_hibernate完整用法.大家可以下载看看.作为参考.
Java_Hibernate QBC条件查询对比
Hibernate中使用Criteria Query各种QBC查询
Hibernate_QBC查询[归类].pdf
Hibernate实例开发 HQL 与 QBC 查询
NULL 博文链接:https://wfq5154.iteye.com/blog/1714952
使用Hibernate的QBC查询,对数据库内容进行分页查询,在控制他显示,可跳转转的页面
Hibernate criteria queris 条件查询(QBC)转 Hibernate QBC查询 QBC分页查询大全
之前也发了一个,这个包含之前的,还添加了hibernate对数据库操作的代码(注意:controller层两个QBC/SQLTest代码不能运行,只是写出了操作数据库的除了HQL的另外2种方式)。我发现现在还是有很多公司用hibernate+...
查询所有 // 2.条件查询 // 3.模糊查询 // 4.范围查询 // 5.排序查询(order by) // 6.分页查询 // 7.投影查询(只获取部分字段的结果) // 8.聚集函数使用(聚合函数)(count、sum、avg、max、min等) // 9.TOP N...
hibernate概述,hibernate入门Demo,hibernate配置文件详解(全局配置,实体类映射配置),配置...hibernate查询方式概述,HQL查询,QBC查询,分页,结果集封装方式 ,高级查询 查询的优化,一级缓存,二级缓存,批量查询,注解方式
QBC的相关讲义和例题 QBC(Query By Criteria)查询方式是Hibernate提供的“更加面向对象”的一种检索方式。QBC在条件查询上比HQL查询更为灵活,而且支持运行时动态生成查询语句。
QBC.QBE查询 hibernate提供的更加面向对象的查询方式 希望对你有所帮助
User实体(id, name, age, sex, ctime),使用hibernate实现User的增删改查。要求: 1、包的层次: com.xxx.entity, com.xxx.dao, com.xxx.dao.impl.hql, com.xxx.dao.impl.qbc, com.xxx.dao.impl.sql, ...
hibernate查询,spring+hibernate
17.1.2 QBC检索方式 17.1.3 本地SQL检索方式 17.1.4 关于本章范例程序 17.1.5 使用别名 17.1.6 多态查询 17.1.7 对查询结果排序 17.1.8 分页查询 17.1.9 检索单个对象(uniqueResult()方法) 17.1...