当前位置:网站首页>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边栏推荐
- Harbor webhook from principle to construction
- 用实际例子详细探究OpenCV的轮廓检测函数findContours(),彻底搞清每个参数、每种模式的真正作用与含义
- redis中value/hush
- CAD如何設置標注小數比特
- Chen Gong: Micro service, is it still so pure?
- Botu V15 add GSD file
- 241. Design priority for operational expressions: DFS application questions
- About keil compiler, "file has been changed outside the editor, reload?" Solutions for
- 陈珙:微服务,它还那么纯粹吗?
- leetcode 406. Queue Reconstruction by Height(按身高重建队列)
猜你喜欢
Seckill system 03 - redis cache and distributed lock
Build yocto system offline for i.mx8mmini development board
Dlhsoft Kanban, Kanban component of WPF
[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 5
NOV Schedule for . Net to display and organize appointments and recurring events
[Maui] add click events for label, image and other controls
陈珙:微服务,它还那么纯粹吗?
uniapp 使用 uni-upgrade-center
Machine learning - Data Science Library - day two
消息队列之监控退款任务批处理过程
随机推荐
邻接矩阵无向图(一) - 基本概念与C语言
The operation process of using sugar to make a large data visualization screen
博途V15添加GSD文件
[MCU] [nixie tube] nixie tube display
CAD如何設置標注小數比特
Uniapp uses uni upgrade Center
Powerful, easy-to-use, professional editor / notebook software suitable for programmers / software developers, comprehensive evaluation and comprehensive recommendation
Message queue monitoring refund task batch process
Redis startup and library entry
On recursion and Fibonacci sequence
基于IMDB评论数据集的情感分析
Force button homepage introduction animation
消息队列之监控退款任务批处理过程
华为HMS Core携手超图为三维GIS注入新动能
Why does the JVM heap memory exceed 32g and pointer compression fail?
用实际例子详细探究OpenCV的轮廓检测函数findContours(),彻底搞清每个参数、每种模式的真正作用与含义
Typora realizes automatic uploading of picture pasting
Value/set in redis
Golang introduces the implementation method of the corresponding configuration file according to the parameters
比特熊直播间一周年,英雄集结令!邀你来合影!