当前位置:网站首页>JPA and criteria API - select only specific columns - JPA & criteria API - select only specific columns
JPA and criteria API - select only specific columns - JPA & criteria API - select only specific columns
2022-07-01 12:07:00 【Saffron】
problem :
I would like to select only specific columns (ex. SELECT a FROM b
). I want to select only specific columns ( for example SELECT a FROM b
).I have a generic DAO and what I came up with is: I have a general DAO, What I came up with was :
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();}
And the error is: The method select(Selection<? extends T>) in the type CriteriaQuery<T> is not applicable for the arguments (Path<Object>)
. The error is : The method select(Selection<? extends T>) in the type CriteriaQuery<T> is not applicable for the arguments (Path<Object>)
.How should I change that? How can I change ?I want to get a type T
object that has only ID
and VERSION
fields, and all others are null
. I want to get one only ID
and VERSION
Field T
object , All other objects are null
.
Type T
extends AbstractEntity
which has those 2 fields. type T
Expand AbstractEntity
, It has these two fields .
entityClazz
is T.class
.entityClazz
yes T.class
.
Solution :
Reference resources : https://stackoom.com/en/question/qwe1边栏推荐
- 用实际例子详细探究OpenCV的轮廓检测函数findContours(),彻底搞清每个参数、每种模式的真正作用与含义
- 自定義 grpc 插件
- C knowledge point form summary 2
- Emotion analysis based on IMDB comment data set
- Typora adds watermarks to automatically uploaded pictures
- Sum of factor numbers of interval product -- prefix sum idea + fixed one shift two
- Prepare for the Blue Bridge Cup Day10__ PWM control light brightness
- Machine learning - Data Science Library - day two
- Abbirb120 industrial robot mechanical zero position
- On recursion and Fibonacci sequence
猜你喜欢
The Missing Semester
Deep understanding of grpc part1
GID:旷视提出全方位的检测模型知识蒸馏 | CVPR 2021
LeetCode力扣(剑指offer 31-35)31. 栈的压入弹出序列32I.II.III.从上到下打印二叉树33. 二叉搜索树的后序遍历序列34. 二叉树中和为某一值的路径35. 复杂链表的复制
Huawei HMS core joins hands with hypergraph to inject new momentum into 3D GIS
Learning summary on June 29, 2022
强大、好用、适合程序员/软件开发者的专业编辑器/笔记软件综合评测和全面推荐
91. (cesium chapter) cesium rocket launch simulation
Acly and metabolic diseases
消息队列之监控退款任务批处理过程
随机推荐
Seckill system 03 - redis cache and distributed lock
巩固-C#运算符
Personnaliser le plug - in GRPC
Redis common sense
Typora realizes automatic uploading of picture pasting
耐克如何常年霸榜第一名?最新財報答案來了
[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 3
【单片机】【数码管】数码管显示
华为HMS Core携手超图为三维GIS注入新动能
How to set decimal places in CAD
图的理论基础
Golang根据参数引入相应配置文件的实现方式
Theoretical basis of graph
91. (chapitre Cesium) simulation de lancement de fusées cesium
[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 8
C summary of knowledge points 1
Comment Nike a - t - il dominé la première place toute l'année? Voici les derniers résultats financiers.
深入理解 grpc part1
Share the method of how to preview PSD format and PSD file thumbnail plug-in [easy to understand]
消息队列之监控退款任务批处理过程