I want to set an OneToOne entity using a Formula.
I have tried the following but the result is always null (I guess because the co
@Formula is ignored, because it is only valid as replacement for @Column. And that one is not used for relationships mappings.
But you can use @Where instead, which exists for collections:
@OneToMany
@JoinTable(name = "PRODUCTION_MEDIAASSET_NEW", joinColumns = @JoinColumn(name = "PRODUCTION_ORDER_ID", referencedColumnName = "MEDIAASSET_ORDER_ID"))
@Where("KEY_TEXT = 1")
private Collection keyMediaAsset;
To access your original keyMediaAsset object you can use a specific getter:
public MediaAssetOrder getKeyMediaAsset() {
return keyMediaAsset.isEmpty() ? null : keyMediaAsset.iterator().next();
}