EntityManager.getResultList()不返回预期结果

时间:2017-10-11 14:24:52

标签: sql entitymanager

select a.AssignAccOwner,a.AssignBillRate,a.AssignPerdiem from orion_db.assignment as a where a.AssignmentId=25

我能够成功执行上述查询。但是当我尝试使用entityManager.createnativeQuery以编程方式执行相同的查询时,我将resultList设置为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实体类

/ **  *由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;
        }

    }

1 个答案:

答案 0 :(得分:0)

这不是代码问题,我没有连接到本地数据库,因此我没有得到预期的结果..