2017-03-05 5 views
1

エラーHibernateの基準は、複数の投影これら3は、文字列型であるJPAエンティティのカスタムPOJO

Hibernate: select this_.UID as y0_, this_.PATH as y1_, this_.NAME as y2_ from AWARD this_ where this_.DELETED=? 
    java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Boolean 

休止状態コードに

criteria.add(Restrictions.eq("deleted", 0)); 
     criteria.setProjection(Projections.projectionList().add(Projections.property("uid")) 
       .add(Projections.property("path")).add(Projections.property("name"))). 
     setResultTransformer(Transformers.aliasToBean(AwardsInSession.class)); 

     List<AwardsInSession> la = criteria.list(); 

Custorm POJO

public class AwardsInSession extends BaseModel{ 
    private String uid; 

    private String path; 

    private String name; 

を結ん

答えて

1

、以下のコードは動作します。我々はTransformers.aliasToBeanを使用しているとして、基準の蓄積の各列は

criteria 
      .add(Restrictions.eq("deleted", Boolean.FALSE)) 
      .add(Restrictions.eq("orgId.id", orgId)) 
      .setProjection(Projections.projectionList() 
        .add(Projections.alias(Projections.property("path"), "path")) 
        .add(Projections.alias(Projections.property("uid"), "uid")) 
        .add(Projections.alias(Projections.property("name"), "name"))) 
      .setResultTransformer(Transformers.aliasToBean(AwardsInSession.class)); 
+0

はい、良い点です –

0

あなたのAwでブール値としてdeletedプロパティフィールドが定義されています。

したがって、あなたの制限は次のようになります。それを修正

criteria.add(Restrictions.eq("deleted", Boolean.FALSE)); 
+0

感謝の男が例外を処分したエイリアスを持っている必要がありますが、私は alowsarwar

+0

をいただきまし例外リストへの値を得ることができませんでした? –

+0

例外はありませんが、AwardsInSessionのすべての値はnullです。このクエリは、1行 – alowsarwar

関連する問題