开发者

Result for a projection's list with a hibernate criteria

I'm using a criteria with projections to extract 2 columns from m开发者_高级运维y database. However, I would like a result as 2 lists of simple elements instead of 1 list of elements.

My criteria :

final DetachedCriteria criteria = DetachedCriteria.forClass(Valeur.class, "value") .add(Restrictions.eq("value.parametre.id", parameterId)) (... more restrictions ...) criteria.setProjection( Projections.distinct( Projections.projectionList() .add( Projections.property( "value.valeurVal" ) ) .add( Projections.property( "measure.mesureDate" ) ) ) );

    criteria.addOrder( Order.asc("measure.mesureDate") );

final List<Data> result =  (List<Data>)  criteria.getExecutableCriteria(_sessionFactory.getCurrentSession()).list();

My Data object :

private double _value;
@NotNull
private Date _date;

In this case, I have a list of Data, but I want to have TWO lists : one of double and the other of Date. Is this possible ? Any idea ?

Thanks a lot for your help. vanessa


Once you have the return list, you can output it manually into two lists:

List<String> stringList = new ArrayList<String>();
List<Integer> integerList = new ArrayList<Integer>();
results = criteria.list();
if(results != null) {
    for (Object[] row : results) {
        stringList.add((String)row[0]);
        integerList.add((Integer)row[1]);
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜