ICriteria
スーパークラスからプロパティを返す がありますAnimal
。ここで、サブクラスのいくつかのプロパティを結果に含めたいと思いますBird
。他のサブクラスの場合、これらのプロパティは を返す必要がありnull
ます。サブクラスごとのテーブル継承を使用しています。たくさん追加せずにこれを行う方法はありますDetachedCriteria
か? Hibernate はすでにサブクラス テーブルに結合を残しています。これらの結合から値を投影する方法はありますか?
更新:サブクラスのプロパティで並べ替えとフィルター処理を行う必要があり、クエリ全体でページングをサポートする必要があります。
これが私のモデルです:
public abstract class Animal
{
public long Id { get; set; }
public string Name { get; set; }
}
public class Cat : Animal
{
public int WhiskerCount { get; set; }
}
public class Bird : Animal
{
public long WingSpan { get; set; }
}
次の表を考えます。
Animal:
Id | Name
----+--------------
1 | Sylvester
2 | Tweety
3 | Maru
4 | Big Bird
Cat:
Id | WhiskerCount
----+--------------
1 | 6
3 | 12
Bird:
Id | Wingspan
----+--------------
2 | 0.5
4 | 10
次の結果セットが必要です。
Id | Name | Wingspan
----+------------+-------------
1 | Sylvester | <null>
2 | Tweety | 0.5
3 | Maru | <null>
4 | Big Bird | 10