springboot jpa---->总结一下遇到的问题
Native Query throw exception
- dto code
import lombok.Value;
@Value
public class IdsOnly {
Integer id;
String otherId;
}
- repository
public interface TestTableRepository extends JpaRepository<TestTable, Integer> {
@Query(value = "select id, otherId from TestTable where CreationDate > ?1", nativeQuery = true)
public Collection<IdsOnly> findEntriesAfterDate(Date creationDate);
}
- service
List<IdsOnly> results = ttRepo.findEntriesAfterDate(theDate);
- exception
org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [org.springframework.data.jpa.repository.query.AbstractJpaQuery$TupleConverter$TupleBackedMap] to type [com.example.IdsOnly]
解决方法有两种
- 使用NativeQuery:将IdsOnly更换成接口,提供属性的get方法。
public interface IdsOnly {
Integer getId();
String getOtherId();
}
- 不使用NativeQuery
@Query("select new com.example.IdsOnly(t.id, t.otherId) from TestTable t where t.creationDate > ?1")
Jpa中没有update方法
jpa中只有save方法,如果你传递的对象的主键在数据库中存在,那么就是更新操作。否则就是插入操作。
Delete operation
JpaRepository Not supported for DML operations [delete query]
- Repository: add
@Modifying
@Modifying
void deleteByUserIdAndToolId(Integer userId, Integer toolId);
- Service: add
@Transactional
@Transactional
public void doDeleteUserTool(Integer userId, Integer toolId) {
userToolMapper.deleteByUserIdAndToolId(userId, toolId);
}
To be continue
Industry is the soul of business and the keystone of prosperity.
springboot jpa---->总结一下遇到的问题的更多相关文章
- 补习系列(19)-springboot JPA + PostGreSQL
目录 SpringBoot 整合 PostGreSQL 一.PostGreSQL简介 二.关于 SpringDataJPA 三.整合 PostGreSQL A. 依赖包 B. 配置文件 C. 模型定义 ...
- 【原】无脑操作:IDEA + maven + Shiro + SpringBoot + JPA + Thymeleaf实现基础授权权限
上一篇<[原]无脑操作:IDEA + maven + Shiro + SpringBoot + JPA + Thymeleaf实现基础认证权限>介绍了实现Shiro的基础认证.本篇谈谈实现 ...
- 【原】无脑操作:IDEA + maven + Shiro + SpringBoot + JPA + Thymeleaf实现基础认证权限
开发环境搭建参见<[原]无脑操作:IDEA + maven + SpringBoot + JPA + Thymeleaf实现CRUD及分页> 需求: ① 除了登录页面,在地址栏直接访问其他 ...
- 带着新人学springboot的应用08(springboot+jpa的整合)
这一节的内容比较简单,是springboot和jpa的简单整合,jpa默认使用hibernate,所以本质就是springboot和hibernate的整合. 说实话,听别人都说spring data ...
- springboot+jpa+mysql+redis+swagger整合步骤
springboot+jpa+MySQL+swagger框架搭建好之上再整合redis: 在电脑上先安装redis: 一.在pom.xml中引入redis 二.在application.yml里配置r ...
- springboot+jpa+mysql+swagger整合
Springboot+jpa+MySQL+swagger整合 创建一个springboot web项目 <dependencies> <dependency> < ...
- SpringBoot JPA + H2增删改查示例
下面的例子是基于SpringBoot JPA以及H2数据库来实现的,下面就开始搭建项目吧. 首先看下项目的整体结构: 具体操作步骤: 打开IDEA,创建一个新的Spring Initializr项目, ...
- SpringBoot Jpa入门案例
版权声明:署名,允许他人基于本文进行创作,且必须基于与原先许可协议相同的许可协议分发本文 (Creative Commons) 我们先来了解一下是什么是springboot jpa,springboo ...
- SpringBoot JPA懒加载异常 - com.fasterxml.jackson.databind.JsonMappingException: could not initialize proxy
问题与分析 某日忽然发现在用postman测试数据时报错如下: com.fasterxml.jackson.databind.JsonMappingException: could not initi ...
- SpringBoot Jpa 自定义查询
SpringBoot Jpa 自定义查询 持久层Domain public interface BaomingDao extends JpaRepository<BaomingBean,Inte ...
随机推荐
- 中国台湾BSMI认证变动
China Taiwan 中国台湾 2022 年 11 月 1 日,BSMI和经济部发布了针对 18 种音像产品的修订法定检验要求. 自发布之日起,CNS 15598-1:2020 Audio/vid ...
- Shell 更多结构化命令(流程控制)
更多的结构化命令 上一章里,你看到了如何通过检查命令的输出和变量的值来改变 shell 脚本程序的流程.本章会继续介绍能够控制 shell 脚本流程的结构化命令.你会了解如何重复一些过程和命令,也就是 ...
- 3、一个简单的Java应用程序
/* 1.Java中区分大小写,如果出现了大小写拼写错误,例如将main拼写成Main,则程序将无法运行. 2.关键字public成为访问修饰符,用来控制程序的其他部分对这段代码的访问级别. 3.关键 ...
- openstack安装部署私有云详细图文
本文主要分享的是云计算.openstack的使用.私有云平台建设.云服务器云硬盘的构建和使用.从基本概念入手到私有云建设,信息量非常大.对于openstack的安装部署都是从官方文档中一步步的介绍,内 ...
- 如果遇到This QueryDict instance is immutable错误
添加数据的时候,大家遇到"This QueryDict instance is immutable". 唯一的解决方法是request.data.copy()即可成功实现添加功能
- SpringMVC配置文件applicationContext.xml头信息
applicationContext.xml头信息 <?xml version="1.0" encoding="UTF-8"?> <beans ...
- RabbitMq安装配置启动
RabbitMq安装配置启动 一:安装材料 请前往官方地址下载 Erlang: https://www.erlang.org/downloads rabbitmq: https://www.rabbi ...
- 利用shell脚本提高访问GitHub速度
Github由于做了域名限制,所以访问比较慢,编写了个脚本达到做本地域名解析提高GitHub的访问速度 #!/usr/bin/env bash # 该脚本用来提升github的访问速度 ROOT_UI ...
- 线程安全与数据结构JAVA
线程 线程与进程本质的区别在于每个进程拥有自己的一整套变量, 而线程之间可以有共享变量.另外创建.销毁一个线程的代价比启动新进程的代价要小. 在java中,没有可以强制线程终止的方法,然而, inte ...
- 【Unity】阅读LuaFramework_UGUI的一种方法
写在前面 我第一次接触到LuaFramework_UGUI是在一个工作项目中,当时也是第一次知道toLua.但我刚开始了解LuaFramework_UGUI时十分混乱,甚至将LuaFramework_ ...