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 ...
随机推荐
- nginx 添加ssl认证,访问静态资源 笔记
1.查看是否开启SSL模块, /usr/local/nginx/sbin ./nginx -V 2.没有开启,进入到nginx源码包目录下: 3编译 ./configure --prefix= ...
- JS中Promise
Promise的作用: Promise是异步微任务,解决了异步多层嵌套回调的问题,让代码的可读性更高,更容易维护. Promise如何使用: Promise是ES6提供的一个构造函数,可以使用Prom ...
- Windows如何生成公钥和私钥
Windows如何生成公钥和私钥 方法一)使用git命令 一. 首先安装git二. 桌面上右键 Git Bash Here三. 命令ssh-keygen -t rsa然后 一直enter 四. 将公钥 ...
- Vue获取DOM的几种方法
虽然Vue实现了MVVM模型,将数据和表现进行了分离,我们只需要更新数据就能使DOM同步更新,但是某些情况下,还是需要获取DOM元素进行操作(比如引入的某个库要求传入一个根dom元素作为根节点,或者写 ...
- 【LeetCode】 907 子数组的最小值之和
Decrisption Given an array of integers arr, find the sum of min(b), where b ranges over every (conti ...
- nuxt中asyncData和fetch的区别
asyncData作用于页面pages,在组件中不能使用,并且asyncData中没有this,如果想要给data中的数据赋值,要在asyncData函数中return出去 fetch 作用于组件中c ...
- jsp第九周作业
1.做一个图书类Book id,name,price ,get,set访问器,构造方法2个,1个无参,1个有参做一个测试类,在main中创建3个图书对象,放到list集合中.做一个菜单,可以添加,删除 ...
- 关于cmake找不到库的问题
1. Error:Could not find a configuration file for package 解决办法1:将/usr/lib/x86_64-linux-gnu/cmake/.... ...
- golang sync.WaitGroup错误使用导致死锁以及noCopy结构体介绍
背景 项目中遇到死锁,使用搜索引擎搜索goroutine堆栈中出现的"sync.runtime_Semacquire deadlock"时,搜到一篇说sync.WaitGroup死 ...
- 【内存管理】CMA内存分配器(Contiguous Memory Allocator)
什么是CMA 参考这两篇博文,写得很好: http://www.wowotech.net/memory_management/cma.html https://www.cnblogs.com/Loye ...