I have the following Java Entity classes:
@MapsSuperClass
class Request {
@OneToMany
List<Parameter> parameters;
String service;
}
@Entity
class PersistedRequest extends Request {
@Id
String id;
}
@Embeddable
class Parameter {
String key;
String value;
}
I want the data to be mapped to a DB Schema like this:
PersistedRequest | ParameterEntity
ID SERVICE | REQUESTID KEY VALUE
\------v------/
Parameter
\--------v---------/
ParameterPK
The Parameter entity has no unique ID value on the java entity, but the combination Request ID + key is unique. So I created two entities to be able to store the parameters EmbeddedID class:
@Embeddable
class ParameterPK {
String requestId;
String key;
}
@Entity
class ParameterEntity {
@EmbeddedId
ParameterPK id;
@Embedded
Parameter parameter;
}
My main question is:
(How) can I somehow map the List on the request class to the database schema above (where Parameter is embedded inside the ParameterEntity)? I do not want to change the java entities (e.g. to put the ParameterEntity inside the Request instead of the Parameter).
How do I make the annotations for the ParameterEntity, ParameterPK and Parameter where the key column is shared between ParameterPK and Parameter?