Hello there! We have the following schema:
MEDIA{
ID}
METADATA{
ID
DESCRIPTION}
MEDIA_METADATA{
ID_MEDIA
ID_METADATA
}
METADATA_VALUE{
ID_MEDIA
ID_METADATA
VALUE
}
The whole idea here is that a Media has a collection of metadata elements. Each metadata has a collection of values. So let's say I have a metadata named "TAG" I would have just one entry on METADATA:
ID:1
VALUE:TAG
And a Media has many tags: soccer, world cup, etc...
ID_MEDIA:1
ID_METADATA:1
VALUE:soccer
ID_MEDIA:1
ID_METADATA:1
VALUE:world cup
and I would like to map this as:L
Code:
public Class Media{
@OneToMany
@JoinTable(name="MEDIA_METADATA", joinColumns=@JoinColumn(name="METADATA_ID"),inverseJoinColumns=@JoinColumn(name="MEDIA_ID"))
protected Set<Metadata> metadata;
...
}
public class Metadata extends BaseEntity {
@CollectionOfElements(targetElement=java.lang.String.class)
@JoinTable(name="METADATA_MEDIA_VALUE", joinColumns={@JoinColumn(name="MEDIA_ID"),@JoinColumn(name="METADATA_ID")})
@Column(name="VALUE_ATTR")
private List<String> values;
...
This is my problem, the Metadata table has only one key METADATA_ID but since the relationship is resolved using a Ternary table, I was hopping I could use the key from that table to propagate the value.
Is it possible to map this relationship? Using those tables?
Regards