2017-10-11 176 views
0
select a.AssignAccOwner,a.AssignBillRate,a.AssignPerdiem from orion_db.assignment as a where a.AssignmentId=25 

我能夠成功執行上述查詢。但是,當我嘗試編程方式使用entityManager.createnativeQuery我收到resultList爲0 下面是要執行的代碼相同的查詢EntityManager.getResultList()不返回預期結果

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; 
     } 

    } 
+0

你爲什麼不嘗試:'entityManager.createNativeQuery(「選擇。 AssignAccOwner,a.AssignBillRate,a.AssignPerdiem from orion_db.assignment as a.AssignmentId =?「);''q2.setParameter(1,25);' –

+0

@AtimeneNazim我還是得到了相同的o/p – Thejas

+0

你能發佈你的分配課程? –

回答

0

這不是代碼的問題,我沒有連接到本地數據庫,所以我沒有得到預期的結果..