How to use OneToOne with Hibernate Formula

前端 未结 1 706
余生分开走
余生分开走 2021-01-22 18:53

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

1条回答
  •  失恋的感觉
    2021-01-22 19:13

    @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();
    }
    

    0 讨论(0)
提交回复
热议问题