oracle結果リストを要約リストにバインドしようとしています。しかし、私の要約リストは、私は次のクエリで結果を取得するには、C要求結果型を使用して複数の戻り値を持つ問合せの型付き問合せを作成できません
Summary.class
{
@Autowired
private A a;
@Autowired
private B b;
@Autowired
private C c;
//getters and setters
}
@Enity
class A{
Fields 1..n ;
} // same goes for other classes definition
をDB
のエンティティ私は3つのエンティティクラスA、Bを持っていると定義3つのクラスがありますが、結果はにキャストすることはできません概要オブジェクト
List<Summary> summaryList = entityManager.createQuery("from A a, B b, C c" +
" where a.field1 = b.field1 and a.fValue = :fValue " +
"and b.field3= c.field3", Summary.class)
.setParameter("fValue ", fValue)
.getResultList();
デバッグ: 私はResultsListとが空いていないと私はオブジェクト
0にキャストいけない場合、クエリの下に正常に動作を確認しました私が見List summaryList = entityManager.createQuery("from A a, B b, C c" +
" where a.field1 = b.field1 and a.fValue = :fValue " +
"and b.field3= c.field3")
.setParameter("fValue ", fValue)
.getResultList();
代替1はsummaryListを反復処理し、私はまだテストしていないが、私はそれが
前に鋳造くぼみの仕事以来、クラスキャスト例外を与えるかもしれないと思う。このような個々のリストにそれを割り当てることですfor (int i = 0; i < summaryList.size(); i++) {
Summary s= (Summary) summaryList.get(i); // might be class cast Exception
aList.add(s.getA());
bList.add(s.getB());
}
私が考えているのは dbからクラスAのフィールドリストを取得するだけです。それをAのリストにキャストしてください。それらをすべて取得するまで3回ブルートフォースしてください。
以下私は私はあなたの考えをお聞かせください、私は私のメインのアプローチを考えている新しい質問
Uses a different class to combine multiple entity classes
gets a list back mapped to pojo
を作成する前に見ていくつかの質問を行うには良い方法ですされていますそれが動作すれば。