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 ...
随机推荐
- vue项目中axios跨域设置
最近项目中遇到一个问题,测试环境和线上环境需要调同一个接口(接口地址是线上的),本地开发的时候遇到了跨域的问题,刚开始用了fetch解决的,代码如下 方法一 step1:安装包node-fetch,然 ...
- linux 基线检查
1 检查用户缺省UMASK #cat /etc/profile|sed '/^#/d'|sed '/^$/d'|grep -i "umask" 修改umask vi /etc/pr ...
- 解决linux时间转换为yyyy-MM-dd
linux时间显示为:Tue Nov 30 09:33:04 CST 2021 SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd ...
- LeetCode LCP 2. 分式化简
从最后一项依次叠加 1 class Solution(object): 2 def fraction(self, cont): 3 """ 4 :type cont: L ...
- windows 切换路径
- Python爬虫之用Selenium做爬虫
我们在用python做爬虫的时候,除了直接用requests的架构,还有Scrapy.Selenium等方式可以使用,那么今天我们就来聊一聊使用Selenium如何实现爬虫. Selenium是什么? ...
- X射线随笔
2023-02-27 千里马与伯乐 如果把X射线(X光)比做千里马的话,那这匹千里马的发掘,离不开伯乐的贡献.说起X射线的伯乐,就得从一个简短的故事说起: 1895年11月8日的夜晚,德国物理学家伦琴 ...
- Android 自定义SeekBar (二)
一.前言 本文在 上节 的基础上,讲解自定义拖动条的实现思路. 二.思路 先在res/values文件夹下,自定义控件属性: <?xml version="1.0" enco ...
- Spring AOP @before@after@around@afterreturning@afterthrowing执行顺序
public Object aop(Method method,Object object) { try { try { /*doAround start*/ doBefore(); method.i ...
- ajax的async异步执行属性
遇到了一个ajax,看到了一个属性,async,是用来设置同步执行,或者是异步执行的 举一个例子: $.ajax({ async: false, type : "post", ...