2012-05-24 174 views
0

我有複雜映射的實體,我沒有註釋權。休眠複雜集合映射問題

這裏是實體:

@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映射superbs 請幫助。

回答

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 
} 
不能映射其