from (select new map(a1.name as aa1 ,a2.name as aa2,a3.name as aa3,c.customersname as bb,b.name as name,b.customer_Name as customer_Name,b.account_Manager as account_Manager,b.clients as clients,b.prosection1 as prosection1,b.prosection2 as prosection2,b.prosection3 as prosection3,b.dotime as dotime,b.incometime as incometime,b.itembudget as itembudget,b.re as re) from Pro_segmentDomain as a1,Pro_segmentDomain as a2,Pro_segmentDomain as a3,Item_trackDomain as b ,Customers as c where a1.id=b. prosection1 and a2.id=b. prosection2 and a3.id=b. prosection3 and b.clients=c.customersid)as zz改为 from (select new map(a1.name as aa1 ,a2.name as aa2,a3.name as aa3,c.customersname as bb,b.name as name,b.customer_Name as customer_Name,b.account_Manager as account_Manager,b.clients as clients,b.prosection1 as prosection1,b.prosection2 as prosection2,b.prosection3 as prosection3,b.dotime as dotime,b.incometime as incometime,b.itembudget as itembudget,b.re as re)from Pro_segmentDomain as a1,Pro_segmentDomain as a2,Pro_segmentDomain as a3,Item_trackDomain as b ,Customers as c where a1.id=b. prosection1 and a2.id=b. prosection2 and a3.id=b. prosection3 and b.clients=c.customersid)as zz 无空格看看
或者,给 Pro_segmentDomain 定义一个构造函数 用这些字段 a1.name as aa1 ,a2.name as aa2,a3.name as aa3,c.customersname as bb,b.name as name,b.customer_Name as customer_Name,b.account_Manager as account_Manager,b.clients as clients,b.prosection1 as prosection1,b.prosection2 as prosection2,b.prosection3 as prosection3,b.dotime as dotime,b.incometime as incometime,b.itembudget as itembudget,b.re as re 然后 from (select new Pro_segmentDomain (a1.name as aa1 ,a2.name as aa2,a3.name as aa3,c.customersname as bb,b.name as name,b.customer_Name as customer_Name,b.account_Manager as account_Manager,b.clients as clients,b.prosection1 as prosection1,b.prosection2 as prosection2,b.prosection3 as prosection3,b.dotime as dotime,b.incometime as incometime,b.itembudget as itembudget,b.re as re )from Pro_segmentDomain as a1,Pro_segmentDomain as a2,Pro_segmentDomain as a3,Item_trackDomain as b ,Customers as c where a1.id=b. prosection1 and a2.id=b. prosection2 and a3.id=b. prosection3 and b.clients=c.customersid)as zz 这里的 Pro_segmentDomain ,列name 等均为映射对象,非表明
你的Pro_segmentDomain 不是实体吗? 如果Pro_segmentDomain 不是实体,怎么能用 new map之类的hql呢 。 这里我是告诉你在Pro_segmentDomain 中增加一个以 这些字段 a1.name as aa1 ,a2.name as aa2,a3.name as aa3,c.customersname as bb,b.name as name,b.customer_Name as customer_Name,b.account_Manager as account_Manager,b.clients as clients,b.prosection1 as prosection1,b.prosection2 as prosection2,b.prosection3 as prosection3,b.dotime as dotime,b.incometime as incometime,b.itembudget as itembudget,b.re as re 的类构造函数
参考我写的: List list = s.createQuery("select new SshPost(postName,postNo,postId) from SshPost").list(); 或者:List list = s.createQuery("select new vo.B(postName,postNo,postId) from SshPost").list(); System.out.println(list.size());public class SshPost { private String postId; private String postName; private String postNo; public String getPostNo() { return postNo; } public void setPostNo(String postNo) { this.postNo = postNo; } // private Integer postNo; // public Integer getPostNo() { // return postNo; // } // public void setPostNo(Integer postNo) { // this.postNo = postNo; // } public String getPostId() { return postId; } public void setPostId(String postId) { this.postId = postId; } public String getPostName() { return postName; } public void setPostName(String postName) { this.postName = postName; } public SshPost() {
} public SshPost(String postId, String postName, String postNo) { super(); this.postId = postId; this.postName = postName; this.postNo = postNo; } }注意这里的B实体可以是任意一个自己定义的bean,以就是说,B不一定非要为数据表的映射实体 public class B { private String postId; private String postName; private String postNo; public String getPostNo() { return postNo; } public void setPostNo(String postNo) { this.postNo = postNo; } // private Integer postNo; // public Integer getPostNo() { // return postNo; // } // public void setPostNo(Integer postNo) { // this.postNo = postNo; // } public String getPostId() { return postId; } public void setPostId(String postId) { this.postId = postId; } public String getPostName() { return postName; } public void setPostName(String postName) { this.postName = postName; } public B() {
from (select new map(a1.name as aa1 ,a2.name as aa2,a3.name as aa3,c.customersname as bb,b.name as name,b.customer_Name as customer_Name,b.account_Manager as account_Manager,b.clients as clients,b.prosection1 as prosection1,b.prosection2 as prosection2,b.prosection3 as prosection3,b.dotime as dotime,b.incometime as incometime,b.itembudget as itembudget,b.re as re)from Pro_segmentDomain as a1,Pro_segmentDomain as a2,Pro_segmentDomain as a3,Item_trackDomain as b ,Customers as c where a1.id=b. prosection1 and a2.id=b. prosection2 and a3.id=b. prosection3 and b.clients=c.customersid)as zz
无空格看看
Pro_segmentDomain 定义一个构造函数
用这些字段
a1.name as aa1 ,a2.name as aa2,a3.name as aa3,c.customersname as bb,b.name as name,b.customer_Name as customer_Name,b.account_Manager as account_Manager,b.clients as clients,b.prosection1 as prosection1,b.prosection2 as prosection2,b.prosection3 as prosection3,b.dotime as dotime,b.incometime as incometime,b.itembudget as itembudget,b.re as re
然后
from (select new Pro_segmentDomain (a1.name as aa1 ,a2.name as aa2,a3.name as aa3,c.customersname as bb,b.name as name,b.customer_Name as customer_Name,b.account_Manager as account_Manager,b.clients as clients,b.prosection1 as prosection1,b.prosection2 as prosection2,b.prosection3 as prosection3,b.dotime as dotime,b.incometime as incometime,b.itembudget as itembudget,b.re as re
)from Pro_segmentDomain as a1,Pro_segmentDomain as a2,Pro_segmentDomain as a3,Item_trackDomain as b ,Customers as c where a1.id=b. prosection1 and a2.id=b. prosection2 and a3.id=b. prosection3 and b.clients=c.customersid)as zz
这里的
Pro_segmentDomain ,列name 等均为映射对象,非表明
谢谢 是我要的 但是关于 select new map 的构造函数 那还不是很明白
这里的
Pro_segmentDomain ,列name 等均为映射对象,非表明
这个意思 是不是再构造一个实体呢?
如果Pro_segmentDomain 不是实体,怎么能用 new map之类的hql呢
。
这里我是告诉你在Pro_segmentDomain 中增加一个以
这些字段
a1.name as aa1 ,a2.name as aa2,a3.name as aa3,c.customersname as bb,b.name as name,b.customer_Name as customer_Name,b.account_Manager as account_Manager,b.clients as clients,b.prosection1 as prosection1,b.prosection2 as prosection2,b.prosection3 as prosection3,b.dotime as dotime,b.incometime as incometime,b.itembudget as itembudget,b.re as re
的类构造函数
List list = s.createQuery("select new SshPost(postName,postNo,postId) from SshPost").list();
或者:List list = s.createQuery("select new vo.B(postName,postNo,postId) from SshPost").list(); System.out.println(list.size());public class SshPost
{
private String postId;
private String postName;
private String postNo;
public String getPostNo() {
return postNo;
}
public void setPostNo(String postNo) {
this.postNo = postNo;
}
// private Integer postNo;
// public Integer getPostNo() {
// return postNo;
// }
// public void setPostNo(Integer postNo) {
// this.postNo = postNo;
// }
public String getPostId() {
return postId;
}
public void setPostId(String postId) {
this.postId = postId;
}
public String getPostName() {
return postName;
}
public void setPostName(String postName) {
this.postName = postName;
}
public SshPost() {
}
public SshPost(String postId, String postName, String postNo) {
super();
this.postId = postId;
this.postName = postName;
this.postNo = postNo;
}
}注意这里的B实体可以是任意一个自己定义的bean,以就是说,B不一定非要为数据表的映射实体
public class B
{
private String postId;
private String postName;
private String postNo;
public String getPostNo() {
return postNo;
}
public void setPostNo(String postNo) {
this.postNo = postNo;
}
// private Integer postNo;
// public Integer getPostNo() {
// return postNo;
// }
// public void setPostNo(Integer postNo) {
// this.postNo = postNo;
// }
public String getPostId() {
return postId;
}
public void setPostId(String postId) {
this.postId = postId;
}
public String getPostName() {
return postName;
}
public void setPostName(String postName) {
this.postName = postName;
}
public B() {
}
public B(String postId, String postName, String postNo) {
super();
this.postId = postId;
this.postName = postName;
this.postNo = postNo;
}
}
每个map里包含两个元素