2013-03-25 46 views
0

我有表在Hibernate中的代碼是在這裏問題在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表中的數據。 如何使用休眠保存數據。 請幫忙...

+0

請發表您的代碼,你正試圖保存數據。 – 2013-03-25 13:28:14

+0

@ jordan002實際上我無法理解如何保存它,我剛剛創建了一個會話和事務對象。我有CDSCurve的對象,它具有所有的數據,但我將如何存儲Subordination ID? – Azuu 2013-03-25 13:30:48

回答