我正在尝试从hibernate中获取数据我已经使用Embeded类跟随Entity。
实体
@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_
当我通过Client触发相同的结果时,它给了我结果。但是当我检查Hibernate返回的列表时,它给了Collection
,它有没有。每个字段的行为null
请帮助
答案 0 :(得分:0)
尝试hql。
之类的东西 Query query = session.createQuery("from NewReconnectPts1Id);
List list = query.list();