【hibernate多表连接 查询的解决方案】
2013-10-05 16:01
302 查看
大家在用hibernate的时候总会遇到多表连接的查询,遇到这种问题 总是各种纠结。
方案1:建立视图 ,事先在数据库里面建立视图。然后建立这个视图的实体类,指定一个主键。然后建立这个视图的查询。
方案2:给实体类加临时属性HQL查询补充。
上代码:
实体类:
@Entity
@Table(name = "FLOW_RU_INFO")
public class FlowRuInfo implements java.io.Serializable {
// Fields
private String id;
private String deptid;
private String processinstanceid;
private String content;
private String creator;
private Date createtime;
private String flowtype;
private String flowcode;
private String formid;
private String state;
private String currentuserid;
private String pflowtype;
private String formNo;
//临时属性
private String task;
private String lastAudiUser;
private String nextUser;
private String userName;
private String deptName;
// Constructors
/** default constructor */
public FlowRuInfo() {
}
public FlowRuInfo(String id, String deptid, String processinstanceid,
String content, String creator, Date createtime, String flowtype,
String flowcode, String formid, String state, String currentuserid,
String pflowtype, String formNo, String task, String lastAudiUser,
String nextUser, String userName, String deptName) {
super();
this.id = id;
this.deptid = deptid;
this.processinstanceid = processinstanceid;
this.content = content;
this.creator = creator;
this.createtime = createtime;
this.flowtype = flowtype;
this.flowcode = flowcode;
this.formid = formid;
this.state = state;
this.currentuserid = currentuserid;
this.pflowtype = pflowtype;
this.formNo = formNo;
this.task = task;
this.lastAudiUser = lastAudiUser;
this.nextUser = nextUser;
this.userName = userName;
this.deptName = deptName;
}
// Property accessors
@GenericGenerator(name = "generator", strategy = "uuid.hex")
@Id
@GeneratedValue(generator = "generator")
@Column(name = "ID", unique = true, nullable = false, length = 32)
public String getId() {
return this.id;
}
public void setId(String id) {
this.id = id;
}
@Column(name = "DEPTID", length = 32)
public String getDeptid() {
return this.deptid;
}
public void setDeptid(String deptid) {
this.deptid = deptid;
}
@Column(name = "PROCESSINSTANCEID", length = 100)
public String getProcessinstanceid() {
return this.processinstanceid;
}
public void setProcessinstanceid(String processinstanceid) {
this.processinstanceid = processinstanceid;
}
@Column(name = "CONTENT", length = 800)
public String getContent() {
return this.content;
}
方案1:建立视图 ,事先在数据库里面建立视图。然后建立这个视图的实体类,指定一个主键。然后建立这个视图的查询。
方案2:给实体类加临时属性HQL查询补充。
上代码:
实体类:
@Entity
@Table(name = "FLOW_RU_INFO")
public class FlowRuInfo implements java.io.Serializable {
// Fields
private String id;
private String deptid;
private String processinstanceid;
private String content;
private String creator;
private Date createtime;
private String flowtype;
private String flowcode;
private String formid;
private String state;
private String currentuserid;
private String pflowtype;
private String formNo;
//临时属性
private String task;
private String lastAudiUser;
private String nextUser;
private String userName;
private String deptName;
// Constructors
/** default constructor */
public FlowRuInfo() {
}
public FlowRuInfo(String id, String deptid, String processinstanceid,
String content, String creator, Date createtime, String flowtype,
String flowcode, String formid, String state, String currentuserid,
String pflowtype, String formNo, String task, String lastAudiUser,
String nextUser, String userName, String deptName) {
super();
this.id = id;
this.deptid = deptid;
this.processinstanceid = processinstanceid;
this.content = content;
this.creator = creator;
this.createtime = createtime;
this.flowtype = flowtype;
this.flowcode = flowcode;
this.formid = formid;
this.state = state;
this.currentuserid = currentuserid;
this.pflowtype = pflowtype;
this.formNo = formNo;
this.task = task;
this.lastAudiUser = lastAudiUser;
this.nextUser = nextUser;
this.userName = userName;
this.deptName = deptName;
}
// Property accessors
@GenericGenerator(name = "generator", strategy = "uuid.hex")
@Id
@GeneratedValue(generator = "generator")
@Column(name = "ID", unique = true, nullable = false, length = 32)
public String getId() {
return this.id;
}
public void setId(String id) {
this.id = id;
}
@Column(name = "DEPTID", length = 32)
public String getDeptid() {
return this.deptid;
}
public void setDeptid(String deptid) {
this.deptid = deptid;
}
@Column(name = "PROCESSINSTANCEID", length = 100)
public String getProcessinstanceid() {
return this.processinstanceid;
}
public void setProcessinstanceid(String processinstanceid) {
this.processinstanceid = processinstanceid;
}
@Column(name = "CONTENT", length = 800)
public String getContent() {
return this.content;
}
相关文章推荐
- hibernate多表连接 查询的解决方案
- 【hibernate多表连接 查询的解决方案】
- Hibernate查询解决方案
- Hibernate查询解决方案
- Hibernate Criteria查询之多表连接分页-2【分页封装】
- Hibernate中关于多表连接查询hql 和 sql 返回值集合中对象问题
- [置顶] hibernate复合主键查询主键不能为空的解决方案
- hibernate 实现多表连接查询(简单介绍)
- Hibernate-Criteria查询(2)动态查询、排序、分页、连接查询、投影查询、聚合函数
- Hibernate Criteria查询之多表连接分页-下载连接
- VC++ 通过ADO连接数据库查询时返回空值报错的解决方案
- hibernate 实现多表连接查询 查询结果映射到自定义类中
- Hibernate查询解决方案
- Hibernate连接查询
- hibernate 实现多表连接查询 查询结果映射到自定义类中
- INFORMIX数据库PHP ODBC连接无法插入中文、查询中文的解决方案!!搞了三天啊!!
- Hibernate查询返回list全部为null的解决方案
- hibernate 实现多表连接查询
- Hibernate的连接查询
- hibernate 实现多表连接查询