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---->总结一下遇到的问题的更多相关文章

  1. 补习系列(19)-springboot JPA + PostGreSQL

    目录 SpringBoot 整合 PostGreSQL 一.PostGreSQL简介 二.关于 SpringDataJPA 三.整合 PostGreSQL A. 依赖包 B. 配置文件 C. 模型定义 ...

  2. 【原】无脑操作:IDEA + maven + Shiro + SpringBoot + JPA + Thymeleaf实现基础授权权限

    上一篇<[原]无脑操作:IDEA + maven + Shiro + SpringBoot + JPA + Thymeleaf实现基础认证权限>介绍了实现Shiro的基础认证.本篇谈谈实现 ...

  3. 【原】无脑操作:IDEA + maven + Shiro + SpringBoot + JPA + Thymeleaf实现基础认证权限

    开发环境搭建参见<[原]无脑操作:IDEA + maven + SpringBoot + JPA + Thymeleaf实现CRUD及分页> 需求: ① 除了登录页面,在地址栏直接访问其他 ...

  4. 带着新人学springboot的应用08(springboot+jpa的整合)

    这一节的内容比较简单,是springboot和jpa的简单整合,jpa默认使用hibernate,所以本质就是springboot和hibernate的整合. 说实话,听别人都说spring data ...

  5. springboot+jpa+mysql+redis+swagger整合步骤

    springboot+jpa+MySQL+swagger框架搭建好之上再整合redis: 在电脑上先安装redis: 一.在pom.xml中引入redis 二.在application.yml里配置r ...

  6. springboot+jpa+mysql+swagger整合

    Springboot+jpa+MySQL+swagger整合 创建一个springboot web项目 <dependencies> <dependency>      < ...

  7. SpringBoot JPA + H2增删改查示例

    下面的例子是基于SpringBoot JPA以及H2数据库来实现的,下面就开始搭建项目吧. 首先看下项目的整体结构: 具体操作步骤: 打开IDEA,创建一个新的Spring Initializr项目, ...

  8. SpringBoot Jpa入门案例

    版权声明:署名,允许他人基于本文进行创作,且必须基于与原先许可协议相同的许可协议分发本文 (Creative Commons) 我们先来了解一下是什么是springboot jpa,springboo ...

  9. SpringBoot JPA懒加载异常 - com.fasterxml.jackson.databind.JsonMappingException: could not initialize proxy

    问题与分析 某日忽然发现在用postman测试数据时报错如下: com.fasterxml.jackson.databind.JsonMappingException: could not initi ...

  10. SpringBoot Jpa 自定义查询

    SpringBoot Jpa 自定义查询 持久层Domain public interface BaomingDao extends JpaRepository<BaomingBean,Inte ...

随机推荐

  1. C语言II一作业02

    1.作业头 | 这个作业属于哪个课程 | < https://edu.cnblogs.com/campus/zswxy/SE2020-3> | | ---- | ---- | ---- | ...

  2. Flask默认配置参数

    方式一:字段赋值方式导入 1 2 3 4 5 6 7 8 9 10 11 12 13 14 from flask import Flask   app = Flask(__name__)   app. ...

  3. ESP8266开发(物联网)

    使用开发板制作wifi干扰器https://www.jianshu.com/p/f064ca36ee92

  4. Navicat12安装包+破解方式(详细教程)

    链接:https://pan.baidu.com/s/1vXQzT5nWD73lS5ZMGYYfeA 提取码:phhh 注意!!!  只有Navicat12版本才支持破解,其他版本无法破解. 1. 下 ...

  5. 快速搭建基于webpack的babylon.js开发手脚架

    原文:https://doc.babylonjs.com/how_to/page2 目录 创建一个项目 安装Babylon.js 设置webpack 安装依赖 配置webpack 插件 创建场景 设置 ...

  6. oracle-11.2.0.4静默安装----RedHat7.5

    1.配置/etc/hosts文件和关闭seliux和firewall防火墙 编辑/etc/hosts文件 [root@henry ~]# vim /etc/hosts [root@henry ~]# ...

  7. Educational Codeforces Round 3 个人总结A-D

    Educational Codeforces Round 3 A. USB Flash Drives 降序排序后,贪心,甚至不会爆longlong void solve() { int n,m; ci ...

  8. 如何卸载cdr x8?怎么把cdr x8彻底卸载删除干净重新安装的方法【转载】

    标题:如何卸载cdr x8?怎么把cdr x8彻底卸载删除干净重新安装的方法.cdr x8显示已安装或者报错出现提示安装未完成某些产品无法安装的问题,怎么完全彻底删除清理干净cdr x8各种残留注册表 ...

  9. springboot pom文件引入本地jar包

    记录maven引用本地jar包 配置 及打包的其中一个方法,作为个人笔记,供参考: <dependency> <groupId>gdin</groupId> < ...

  10. 去除input框相关样式,只显示内容

    <input /> css代码: .edit-input{ /* width: 20px; */ height: -webkit-fill-available; background: i ...