我的实体具有复杂的映射,我无法正确注释。
以下是实体:
@Entity
@Table(name = "bank")
class Bank {
@Column(name = "type")
int type
@ElementCollection
@CollectionTable(name = "bank_fp", joinColumns = @JoinColumn(name = "bank_id"))
@MapKeyColumn(name = "finance_percent")
Map<Double, BankRates>
}
? embeddable or entity ?
class BankRates {
@ElementCollection
@CollectionTable(name = "bankrates", joinColumns = @JoinColumn(name = "bfp_id"))
@MapKeyColumn(name = "track_class")
Map<String, TrackRates>
}
? embeddable or entity ?
class TrackRates {
? how to map ?
Map<YearsRange, Double>
}
@Embeddable
@Access(AccessType.FIELD)
class YearsRange {
@Column(name = "from")
int from
@Column(name = "to")
int to
}
在我看来,这些是表格:
Bank: id, type
bank_fp: id, bank_id, finance_percent - table for the map in the bank entity
bank_rates: bfp_id, track_class, from, to, rate - table for BankRates, TrackRates, YearsRange all embedded in a single table cuz its only mappings
那些hibernate映射高超的人 请帮忙。
答案 0 :(得分:0)
@entity class BankRates
因为它有自己的ID
由于bank_rates
包含很多重复的(bfp_id,track_class),你无法将其映射为必须自己实现地图逻辑
class BankRates {
@ElementCollection
@CollectionTable(name = "bankrates", joinColumns = @JoinColumn(name = "bfp_id"))
List<TrackRate>
}
@Embeddable
class TrackRate {
@Column(name = "track_class")
String trackClass;
YearsRange
Double
}
@Embeddable
@Access(AccessType.FIELD)
class YearsRange {
@Column(name = "from")
int from
@Column(name = "to")
int to
}