Reputation: 133
I have a Java bean/model class with JPA annotation as below. This class has a composite key as shown below. In DAO.java
how do I set the key to this composite key?
@EmbeddedId
@AttributeOverrides({
@AttributeOverride(name = "ratioFunctionId", column = @Column(name = "ratio_function_id", nullable = false, scale = 0)),
@AttributeOverride(name = "expressionId", column = @Column(name = "expression_id", nullable = false, scale = 0))
})
public RatioFunctionExpressionId getId() {
return this.id;
}
public void setId(RatioFunctionExpressionId id) {
this.id = id;
}
Upvotes: 0
Views: 2024
Reputation: 27880
In order to set a value for this attribute, just create a new instance and assign it:
RatioFunctionExpressionId newId = new RatioFunctionExpressionId();
newId.setRatioFunctionId(aFunctionId);
newId.setExpressionId(anExpressionId);
aRatioFunctionExpression.setId(newId);
Remember that being RatioFunctionExpressionId
an @Embeddable
, it doesn't need an id of its own, because it doesn't represent an Entity on its own. It's only meant to provide grouping of property definitions for easy composition and modularity.
Upvotes: 1