当前位置:网站首页>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边栏推荐
- Seckill system 03 - redis cache and distributed lock
- 研发效能度量框架解读
- Emotion analysis based on IMDB comment data set
- Learning summary on June 30, 2022
- Sum of factor numbers of interval product -- prefix sum idea + fixed one shift two
- 技术分享 | MySQL:从库复制半个事务会怎么样?
- [Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 7
- 消息队列之监控退款任务批处理过程
- LeetCode 454. Add four numbers II
- Personnaliser le plug - in GRPC
猜你喜欢

Abbirb120 industrial robot mechanical zero position

Learning summary on June 29, 2022

Compile and debug net6 source code

91.(cesium篇)cesium火箭发射模拟

二叉堆(一) - 原理与C实现

强大、好用、适合程序员/软件开发者的专业编辑器/笔记软件综合评测和全面推荐

Prepare for the Blue Bridge Cup Day10__ PWM control light brightness

Exploration and practice of inress in kubernetes

91.(cesium篇)cesium火箭發射模擬

【datawhale202206】pyTorch推荐系统:精排模型 DeepFM&DIN
随机推荐
Computer graduation project asp Net attendance management system vs developing SQLSERVER database web structure c programming computer web page source code project
The operation process of using sugar to make a large data visualization screen
GID:旷视提出全方位的检测模型知识蒸馏 | CVPR 2021
Force button homepage introduction animation
强大、好用、适合程序员/软件开发者的专业编辑器/笔记软件综合评测和全面推荐
Build yocto system offline for i.mx8mmini development board
LeetCode 454. 四数相加 II
Impressive bug summary (continuously updated)
CAD如何设置标注小数位
leetcode 406. Queue Reconstruction by Height(按身高重建队列)
Seckill system 03 - redis cache and distributed lock
Brief explanation of the working principle, usage scenarios and importance of fingerprint browser
谈思生物直播—GENOVIS张洪妍抗体特异性酶切技术助力抗体药物结构表征
Kafuka learning path (I) Kafuka installation and simple use
Value/sortedset in redis
Chen Gong: Micro service, is it still so pure?
CPU 上下文切换的机制和类型 (CPU Context Switch)
usb peripheral 驱动 - cable connect/disconnect
CPI tutorial - asynchronous interface creation and use
Deep understanding of grpc part1