2013-12-09 53 views
0

我想從休眠中獲取數據我有以下實體與嵌入類。休眠嵌入列給出空值

實體

@Entity 
@Table(name = "new_reconnect_pts1", uniqueConstraints = @UniqueConstraint(columnNames = { 
     "carrier_id", "bonus_criterion", "start_date", "end_date" })) 
public class NewReconnectPts1 implements java.io.Serializable { 

    /** 
    * 
    */ 
    private static final long serialVersionUID = -4181934462782746103L; 
    private NewReconnectPts1Id id; 

    public NewReconnectPts1() { 
    } 

    public NewReconnectPts1(NewReconnectPts1Id id) { 
     this.id = id; 
    } 

    @EmbeddedId 
    @AttributeOverrides({ 
      @AttributeOverride(name = "carrierId", column = @Column(name = "carrier_id", nullable = false)), 
      @AttributeOverride(name = "bonusPts", column = @Column(name = "bonus_pts", nullable = false)), 
      @AttributeOverride(name = "bonusCriterion", column = @Column(name = "bonus_criterion", nullable = false, length = 20)), 
      @AttributeOverride(name = "cat", column = @Column(name = "cat", length = 20)), 
      @AttributeOverride(name = "customerType", column = @Column(name = "customer_type", nullable = false, length = 20)), 
      @AttributeOverride(name = "startDate", column = @Column(name = "start_date", nullable = false, length = 3080)), 
      @AttributeOverride(name = "endDate", column = @Column(name = "end_date", nullable = false, length = 3080)), 
      @AttributeOverride(name = "duration", column = @Column(name = "duration", nullable = false, length = 1)), 
      @AttributeOverride(name = "remarks", column = @Column(name = "remarks", length = 30)), 
      @AttributeOverride(name = "expiryDate", column = @Column(name = "expiry_date", nullable = false, length = 3080)), 
      @AttributeOverride(name = "noOfTrans", column = @Column(name = "no_of_trans")), 
      @AttributeOverride(name = "contractId", column = @Column(name = "contract_id")) }) 
    public NewReconnectPts1Id getId() { 
     return this.id; 
    } 

    public void setId(NewReconnectPts1Id id) { 
     this.id = id; 
    } 

} 

嵌入式類

@Embeddable 
public class NewReconnectPts1Id implements java.io.Serializable { 


    private int carrierId; 
    private int bonusPts; 
    private String bonusCriterion; 
    private String cat; 
    private String customerType; 
    private Date startDate; 
    private Date endDate; 
    private char duration; 
    private String remarks; 
    private Date expiryDate; 
    private Integer noOfTrans; 
    private Integer contractId; 

    public NewReconnectPts1Id() { 
    } 


    public NewReconnectPts1Id(int carrierId, int bonusPts, String bonusCriterion, String customerType, Date startDate, Date endDate, char duration, Date expiryDate) { 
     this.carrierId = carrierId; 
     this.bonusPts = bonusPts; 
     this.bonusCriterion = bonusCriterion; 
     this.customerType = customerType; 
     this.startDate = startDate; 
     this.endDate = endDate; 
     this.duration = duration; 
     this.expiryDate = expiryDate; 
    } 
    public NewReconnectPts1Id(int carrierId, int bonusPts, String bonusCriterion, String cat, String customerType, Date startDate, Date endDate, char duration, String remarks, Date expiryDate, Integer noOfTrans, Integer contractId) { 
     this.carrierId = carrierId; 
     this.bonusPts = bonusPts; 
     this.bonusCriterion = bonusCriterion; 
     this.cat = cat; 
     this.customerType = customerType; 
     this.startDate = startDate; 
     this.endDate = endDate; 
     this.duration = duration; 
     this.remarks = remarks; 
     this.expiryDate = expiryDate; 
     this.noOfTrans = noOfTrans; 
     this.contractId = contractId; 
    } 


    @Column(name="carrier_id", nullable=false) 
    public int getCarrierId() { 
     return this.carrierId; 
    } 

    public void setCarrierId(int carrierId) { 
     this.carrierId = carrierId; 
    } 

    @Column(name="bonus_pts", nullable=false) 
    public int getBonusPts() { 
     return this.bonusPts; 
    } 

    public void setBonusPts(int bonusPts) { 
     this.bonusPts = bonusPts; 
    } 

    @Column(name="bonus_criterion", nullable=false, length=20) 
    public String getBonusCriterion() { 
     return this.bonusCriterion; 
    } 

    public void setBonusCriterion(String bonusCriterion) { 
     this.bonusCriterion = bonusCriterion; 
    } 

    @Column(name="cat", length=20) 
    public String getCat() { 
     return this.cat; 
    } 

    public void setCat(String cat) { 
     this.cat = cat; 
    } 

    @Column(name="customer_type", nullable=false, length=20) 
    public String getCustomerType() { 
     return this.customerType; 
    } 

    public void setCustomerType(String customerType) { 
     this.customerType = customerType; 
    } 

    @Column(name="start_date", nullable=false, length=3080) 
    public Date getStartDate() { 
     return this.startDate; 
    } 

    public void setStartDate(Date startDate) { 
     this.startDate = startDate; 
    } 

    @Column(name="end_date", nullable=false, length=3080) 
    public Date getEndDate() { 
     return this.endDate; 
    } 

    public void setEndDate(Date endDate) { 
     this.endDate = endDate; 
    } 

    @Column(name="duration", nullable=false, length=1) 
    public char getDuration() { 
     return this.duration; 
    } 

    public void setDuration(char duration) { 
     this.duration = duration; 
    } 

    @Column(name="remarks", length=30) 
    public String getRemarks() { 
     return this.remarks; 
    } 

    public void setRemarks(String remarks) { 
     this.remarks = remarks; 
    } 

    @Column(name="expiry_date", nullable=false, length=3080) 
    public Date getExpiryDate() { 
     return this.expiryDate; 
    } 

    public void setExpiryDate(Date expiryDate) { 
     this.expiryDate = expiryDate; 
    } 

    @Column(name="no_of_trans") 
    public Integer getNoOfTrans() { 
     return this.noOfTrans; 
    } 

    public void setNoOfTrans(Integer noOfTrans) { 
     this.noOfTrans = noOfTrans; 
    } 

    @Column(name="contract_id") 
    public Integer getContractId() { 
     return this.contractId; 
    } 

    public void setContractId(Integer contractId) { 
     this.contractId = contractId; 
    } 

當我執行程序我得到以下Hibernate查詢

select newreconne0_.carrier_id as col_0_0_, newreconne0_.bonus_pts as col_0_1_, newreconne0_.bonus_criterion as col_0_2_, newreconne0_.cat as col_0_3_, newreconne0_.customer_type as col_0_4_, newreconne0_.start_date as col_0_5_, newreconne0_.end_date as col_0_6_, newreconne0_.duration as col_0_7_, newreconne0_.remarks as col_0_8_, newreconne0_.expiry_date as col_0_9_, newreconne0_.no_of_trans as col_0_10_, newreconne0_.contract_id as col_0_11_ from new_reconnect_pts1 newreconne0_ 

這給我造成WH我通過客戶端啓動了相同的功能,但是當我檢查由Hibernate返回的列表時,它給我提供了Collection,它有no。每場爲null

行請幫

回答

0

嘗試HQL。像

Query query = session.createQuery("from NewReconnectPts1Id); 
List list = query.list(); 
+0

我想同.. – Abhijit

+0

使用HQL編輯器來檢查對象是否返回值或not.if返回值,那麼也許它在你的代碼中的問題。 – Biswajit