2011-09-27 30 views
5

tôi đang cố gắng để tạo ra BO bằng cách tham gia các lớp thực thể của tôiTiêu chuẩn Hibernate Transformers.aliasToBean không Populating giá trị đúng

Criteria criteria = session.createCriteria(Report.class,"r"); 
    criteria 
    .createAlias("template", "t") 
    .createAlias("constituents", "rc") 
    .createAlias("rc.entity", "pe") 
    .createAlias("pe.model", "m") 
    .createAlias("pe.scenario", "s") 
    .setProjection(Projections.projectionList() 
      .add(Projections.property("r.Id"))   
      .add(Projections.property("t.Typ"))     
      .add(Projections.property("pe.bId"))    
      .add(Projections.property("m.model"))    
      .add(Projections.property("s.decay")) 
    ).setMaxResults(100) 
    .addOrder(Order.asc("r.Id")) 
    .setResultTransformer(Transformers.aliasToBean(BO.class)); 

Tôi nhận được 100 BO trống tức là tất cả các thuộc tính là null BO của tôi là như sau

public class BO implements Serializable { 

private static final long serialVersionUID = 1L; 
private int Id; 
private String Typ; 
private String bId; 
private String model; 
private String decay; 

    Getters and Setters 

.....

Khi tôi loại bỏ các dòng aliasToBean vấn và duyệt qua Object [] tôi có thể nhìn thấy các giá trị đúng lấy Hãy hướng dẫn cho tôi ...

Trả lời

14

Hãy thử một cách rõ ràng răng cưa các ProjectionList mục để phù hợp với tên trường trong đậu, như sau:

Criteria criteria = session.createCriteria(Report.class,"r"); 
criteria 
.createAlias("template", "t") 
.createAlias("constituents", "rc") 
.createAlias("rc.entity", "pe") 
.createAlias("pe.model", "m") 
.createAlias("pe.scenario", "s") 
.setProjection(Projections.projectionList() 
     .add(Projections.property("r.Id"), "Id")   
     .add(Projections.property("t.Typ"), "Typ")     
     .add(Projections.property("pe.bId"), "bId")    
     .add(Projections.property("m.model"), "model")    
     .add(Projections.property("s.decay"), "decay") 
).setMaxResults(100) 
.addOrder(Order.asc("r.Id")) 
.setResultTransformer(Transformers.aliasToBean(BO.class)); 
Các vấn đề liên quan