我在 Hibernate 中有表,它的代码在这里
@Entity
@Table(name="CDSCurve")
public class CDSCurve {
private String ticker;
private Subordination subordination;
private String currency;
private float three_m;
private float six_m;
private float nine_m;
private float one_y;
private float two_y;
private float five_y;
private float ten_y;
private float fifteen_y;
private float twenty_y;
private float thirty_y;
@Transient
private String desc;
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public CDSCurve() {
super();
}
public CDSCurve(String ticker, Subordination subordination, String currency,
float three_m, float six_m, float nine_m, float one_y, float two_y,
float five_y, float ten_y, float fifteen_y, float twenty_y,
float thirty_y) {
super();
this.ticker = ticker;
this.subordination = subordination;
this.currency = currency;
this.three_m = three_m;
this.six_m = six_m;
this.nine_m = nine_m;
this.one_y = one_y;
this.two_y = two_y;
this.five_y = five_y;
this.ten_y = ten_y;
this.fifteen_y = fifteen_y;
this.twenty_y = twenty_y;
this.thirty_y = thirty_y;
}
@Id
@Column(name="Ticker")
public String getTicker() {
return ticker;
}
public void setTicker(String ticker) {
this.ticker = ticker;
}
@OneToOne(cascade=CascadeType.ALL)
public Subordination getSubordination() {
return subordination;
}
public void setSubordination(Subordination subordination) {
this.subordination = subordination;
}
@Column
public String getCurrency() {
return currency;
}
public void setCurrency(String currency) {
this.currency = currency;
}
@Column
public float getThree_m() {
return three_m;
}
public void setThree_m(float three_m) {
this.three_m = three_m;
}
@Column
public float getSix_m() {
return six_m;
}
public void setSix_m(float six_m) {
this.six_m = six_m;
}
@Column
public float getNine_m() {
return nine_m;
}
public void setNine_m(float nine_m) {
this.nine_m = nine_m;
}
@Column
public float getOne_y() {
return one_y;
}
public void setOne_y(float one_y) {
this.one_y = one_y;
}
@Column
public float getTwo_y() {
return two_y;
}
public void setTwo_y(float two_y) {
this.two_y = two_y;
}
@Column
public float getFive_y() {
return five_y;
}
public void setFive_y(float five_y) {
this.five_y = five_y;
}
@Column
public float getTen_y() {
return ten_y;
}
public void setTen_y(float ten_y) {
this.ten_y = ten_y;
}
@Column
public float getFifteen_y() {
return fifteen_y;
}
public void setFifteen_y(float fifteen_y) {
this.fifteen_y = fifteen_y;
}
@Column
public float getTwenty_y() {
return twenty_y;
}
public void setTwenty_y(float twenty_y) {
this.twenty_y = twenty_y;
}
@Column
public float getThirty_y() {
return thirty_y;
}
public void setThirty_y(float thirty_y) {
this.thirty_y = thirty_y;
}
}
这里有作为外键的列 SubordinationID。
和其他表是从属
@Entity
@Table(name="Subordination")
public class Subordination {
int subordinationId;
String description;
public Subordination(String description) {
super();
this.description = description;
}
@Id
@Column
@SequenceGenerator(sequenceName="subordination_sequence", name="subordination_sequence")
@GeneratedValue(generator="subordination_sequence")
public int getSubordinationId() {
return subordinationId;
}
public void setSubordinationId(int subordinationId) {
this.subordinationId = subordinationId;
}
@Column
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
我想要的是如何在 CSDCurve 表中插入数据。如何使用休眠保存数据。请帮忙...