0

クエリから Embeddable オブジェクトをクエリすることは可能ですか? ここに私のエンティティがあります:

 @Entity
 @Table(name = "A")
 public class UnitParam implements Serializable {
    ...
    @EmbeddedId
    private UnitParamId unitParamId;
    ....
 }

 @Embeddable
 public class UnitParamId implements Serializable {

    @Column(name = "PcID", nullable = false)
    private short pcId;

    @Column(name = "UnitID", nullable = false)
    private short unitId;

    @Column(name = "ParamID", nullable = false)
    private int paramId;
    ...
 }

 @Entity
 @Table(name = "B")
 public class ParameterMapping extends BasicEntity {

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumns(value = {
        @JoinColumn(name = "PcID", referencedColumnName = "PcID"),
        @JoinColumn(name = "UnitID", referencedColumnName = "UnitID"),
        @JoinColumn(name = "ParamID", referencedColumnName = "ParamID") })
    private UnitParam unitParam;
 ...
 }

失敗するクエリは次のとおりです。

  select p.id, p.name as name, 
   p.unitParam.unitParamId.pcId as processCell,
   p.unitParam.unitParamId.unitId as unit,
   p.unitParam.unitParamId.paramId as paramId 
   from ParameterMapping p


例外: Caused by: org.hibernate.QueryException: could not resolve property: unitParamId of: ParameterMapping [SELECT p.id, p.name as name, p.unitParam.unitParamId.pcId as processCell, p.unitParam.unitParamId. unitParam.unitId ユニット、p.unitParam.unitParamId.paramId として paramId FROM de.koehl.mes.model.ParameterMapping p]


よろしくお願いします。

私は問題を見つけました: 最初の問題は、フィールド/プロパティ アクセスの混合でした。それを修正した後、ManyToOne は列を生成しますが、外部キーは生成しません! でもなんでかわからない!!!!

4

1 に答える 1

0

unitParamにフィールドがないUnitParamIdため、パスp.unitParam.unitParamId.unitParam.unitIdが無効です。クエリをに変更します

select p.id, p.name as name, 
       p.unitParam.unitParamId.pcId as processCell,
       p.unitParam.unitParamId.unitId as unit,
       p.unitParam.unitParamId.paramId as paramId 
from ParameterMapping p

またはさらに良い:

select p.id, p.name as name, 
       unitParam.unitParamId.pcId as processCell,
       unitParam.unitParamId.unitId as unit,
       unitParam.unitParamId.paramId as paramId 
from ParameterMapping p
inner join p.unitParam unitParam
于 2012-07-06T14:18:09.700 に答える