特定の列のみを選択したい (例SELECT a FROM b)。私は一般的なDAOを持っており、思いついたのは次のとおりです。
public List<T> getAll(boolean idAndVersionOnly) {
CriteriaBuilder builder = manager.getCriteriaBuilder();
CriteriaQuery<T> criteria = builder.createQuery(entityClazz);
Root<T> root = criteria.from(entityClazz);
if (idAndVersionOnly) {
criteria.select(root.get("ID").get("VERSION")); // HERE IS ERROR
} else {
criteria.select(root);
}
return manager.createQuery(criteria).getResultList();
}
エラーは次のとおり
The method select(Selection<? extends T>) in the type CriteriaQuery<T> is not applicable for the arguments (Path<Object>)です。どうすればそれを変更できますか? とフィールドのみを持ち、他のすべてが である型Tオブジェクトを取得したいと考えています。IDVERSIONnull
これらの 2 つのフィールドを持つextendsを入力しTますAbstractEntity。
entityClazzですT.class。