单向关系的JPA2注释

时间:2011-03-01 10:55:00

标签: java jpa jpa-2.0

您好
在下面详述的InstrumentConfig类中,JPA2注释应该用于仪器和市场吗?

由于

@Entity
@Access(AccessType.FIELD)
class Instrument {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    long id;

    @Basic
    String code; // EURCHF, GOOG, etc.
}

@Entity
@Access(AccessType.FIELD)
class Market {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    long id;

    @Basic
    String name;
}

@Entity
@Access(AccessType.FIELD)
class InstrumentConfig {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    long id;

    // what JPA2 annotations should instrument and market have?
    Instrument instrument;
    Market market;

    @Basic
    String dataURL
}

1 个答案:

答案 0 :(得分:0)

在最简单的情况下就是这样(外键列默认命名,没有级联等):

@ManyToOne
Instrument instrument;     
@ManyToOne
Market market;