DB tables (not quite SQL but you get the gist..)
definition (
id int, -- PK
type int,
label varchar(20) -- definition label can change over time
)
asset (
id int, -- PK
-- other asset fields...
)
property (
id int, -- PK
asset_id int, -- with FK to asset + on delete cascade
definition_id int, -- with FK to definition + on delete cascade
payload varchar(256)
)
A map of the definition id int to payload (Map<int,String>), like this below, works but that's not what I want.
[Asset class]
@ElementCollection
@CollectionTable(name = "properties",
joinColumns = {@JoinColumn(name = "asset_id", referencedColumnName = "id")})
@MapKeyColumn(name = "definition_id")
@Column(name = "payload")
Map<Integer,String> properties;
Instead, I'm trying to have the following map in my Asset class:
Map<Definition,String> properties;
but can't figure what to do. The @MapKeyJoinColumn annotation is intended to pull a relation out of the a entity-type map value so I cannot complete this below:
@OneToMany(cascade = CascadeType.ALL)
@JoinTable(name = "properties",
joinColumns = {@JoinColumn(name = "asset_id", referencedColumnName = "id")},
//inexistant - inverseJoinColumns = {@JoinColumn(name = "property_id", referencedColumnName = "id")})
@MapKeyJoinColumn(name = "definition_id")
Map<Definition,String> properties;
I want a value-type map value. My 'properties' table has the definition_id so I really just need jpa/hibernate to join a table for the entity key, not the value.
Any clue?