1

次のシナリオがあります。

String プロパティ "A" を持つスーパー クラスと、マップされたスーパー クラスから拡張され、別の文字列プロパティ B を持つサブクラス @Entity があります。

挿入を行う必要はありません。テーブル B に対して選択を行うだけで済みます。

しかし、B クラスをクエリすると、hibernate は B からすべてのプロパティをロードしますが、マップされたスーパー クラスのプロパティはロードされません。 getPropertyA() は常に null を返します。

クラスは次のようになります。

@MappedSuperclass
public abstract class BaseContributorEntity extends BaseEntity<Long> implements Comparable<BaseContributorEntity> {
    private String propertyA;

    @Column(name = "column_a", length = 450)
    public String getPropertyA() {
        return propertyA;
    }

    public void setPropertyA(String value) {
        this.propertyA = value;
    } 
}

@Entity
@Table(name = "work_contributor")
public class WorkContributorEntity extends BaseContributorEntity {
    .... Other properties, including @id ....

    private String propertyB;

    @Column(name = "column_b", length = 450)
    public String getPropertyB() {
        return propertyB;
    }

    public void setPropertyB(String value) {
        this.propertyB = value;
    }

    .... Other setters and getters ....

}

なぜこれが起こっているのか誰かが知っていますか?

マップされたスーパー クラス A のゲッターをオーバーロードする必要がありますか?

私は休止状態3.6.3とJPA 2.0で作業しています

4

1 に答える 1

0

私は長年 @MappedSuperclass を使用してきましたが、うまく機能します。あなたのコード例は正しいです。実際のコードを再確認してください。手作業によるエラーがあるはずです。

于 2013-03-11T16:23:31.963 に答える