Search code examples
listormgeneric-listapache-cayenne

Apache Cayenne performQuery result List cast


I am using 3.0 Apache Cayenne, how can I ommit @SuppressWarnings("unchecked") in Eclipse for such simple code:

public List<Some> getSomes() {
    SelectQuery select = new SelectQuery(Some.class);
    List<Some> somes = dbContext.performQuery(select);
    return somes;
}

I cannot find any solution, is it because (I think) performQuery retuns an object List ?


Solution

  • Generics in queries is a feature available since Cayenne 3.2. In 3.2 you'd run queries like this, getting type-safe results:

    SelectQuery<Some> select = new SelectQuery<>(Some.class);
    List<Some> somes = dbContext.select(select);
    

    But there will be 'unchecked' warnings if you are using 3.0. There's no way around this.