EntityManager.getResultList() 没有 return 预期的结果
EntityManager.getResultList() does not return the expected result
select a.AssignAccOwner,a.AssignBillRate,a.AssignPerdiem from orion_db.assignment as a where a.AssignmentId=25
我能够成功执行上述查询。但是当我尝试使用 entityManager.createnativeQuery 以编程方式执行相同的查询时,我得到的结果列表为 0
下面是代码
buff.append("select a.AssignAccOwner,a.AssignBillRate,a.AssignPerdiem from orion_db.assignment as a where a.AssignmentId=25");
Query q2 = entityManager.createNativeQuery(buff.toString());
resultList = q2.getResultList();
System.out.println("Geting the resultList in dao layer " + q2.getResultList().size());
System.out.println("Geting the result in dao layer " + resultList.size());
这是我在日志中得到的结果
Geting the resultList in dao layer 0
Geting the result in dao layer 0
下面是 assignment.java 实体 class
/**
* 由 hbm2java 生成的赋值
*/
@Entity
@Table(name = "assignment")
public class Assignment implements java.io.Serializable {
private static final long serialVersionUID = 1L;
private Integer assignmentId;
private String assignAccOwner;
private BigDecimal assignBillRate;
private String assignPerdiem;
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "AssignmentId", unique = true, nullable = false)
public Integer getAssignmentId() {
return this.assignmentId;
}
public void setAssignmentId(Integer assignmentId) {
this.assignmentId = assignmentId;
}
@Column(name = "AssignBillRate", precision = 10)
public BigDecimal getAssignBillRate() {
return this.assignBillRate;
}
public void setAssignBillRate(BigDecimal assignBillRate) {
this.assignBillRate = assignBillRate;
}
@Column(name = "AssignPerdiem", length = 30)
public String getAssignPerdiem() {
return this.assignPerdiem;
}
public void setAssignPerdiem(String assignPerdiem) {
this.assignPerdiem = assignPerdiem;
}
@Column(name = "AssignAccOwner", length = 100)
public String getAssignAccOwner() {
return this.assignAccOwner;
}
public void setAssignAccOwner(String assignAccOwner) {
this.assignAccOwner = assignAccOwner;
}
}
这不是代码问题,我没有连接到本地数据库,因此没有得到预期的结果..
select a.AssignAccOwner,a.AssignBillRate,a.AssignPerdiem from orion_db.assignment as a where a.AssignmentId=25
我能够成功执行上述查询。但是当我尝试使用 entityManager.createnativeQuery 以编程方式执行相同的查询时,我得到的结果列表为 0 下面是代码
buff.append("select a.AssignAccOwner,a.AssignBillRate,a.AssignPerdiem from orion_db.assignment as a where a.AssignmentId=25");
Query q2 = entityManager.createNativeQuery(buff.toString());
resultList = q2.getResultList();
System.out.println("Geting the resultList in dao layer " + q2.getResultList().size());
System.out.println("Geting the result in dao layer " + resultList.size());
这是我在日志中得到的结果
Geting the resultList in dao layer 0
Geting the result in dao layer 0
下面是 assignment.java 实体 class
/** * 由 hbm2java 生成的赋值 */
@Entity
@Table(name = "assignment")
public class Assignment implements java.io.Serializable {
private static final long serialVersionUID = 1L;
private Integer assignmentId;
private String assignAccOwner;
private BigDecimal assignBillRate;
private String assignPerdiem;
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "AssignmentId", unique = true, nullable = false)
public Integer getAssignmentId() {
return this.assignmentId;
}
public void setAssignmentId(Integer assignmentId) {
this.assignmentId = assignmentId;
}
@Column(name = "AssignBillRate", precision = 10)
public BigDecimal getAssignBillRate() {
return this.assignBillRate;
}
public void setAssignBillRate(BigDecimal assignBillRate) {
this.assignBillRate = assignBillRate;
}
@Column(name = "AssignPerdiem", length = 30)
public String getAssignPerdiem() {
return this.assignPerdiem;
}
public void setAssignPerdiem(String assignPerdiem) {
this.assignPerdiem = assignPerdiem;
}
@Column(name = "AssignAccOwner", length = 100)
public String getAssignAccOwner() {
return this.assignAccOwner;
}
public void setAssignAccOwner(String assignAccOwner) {
this.assignAccOwner = assignAccOwner;
}
}
这不是代码问题,我没有连接到本地数据库,因此没有得到预期的结果..