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. SQL Sever ——基础篇之数据库的基本操作

    数据库定义:对数据进行存储喝管理 数据库的系统模型:层次型,网状型,关系型(主流)和对象关系型. 关系型:Realation model 关系-->行列交叉.形式:表示实体和实体间相互联系的数据 ...

  2. Element UI 父组件el-tabel选择某行跳转子组件,在子组件的el-table中选择数组,添加到父组件操作行中

    解决思路: 1.在父组件选择操作某行数据时,将父组件的行号暂存(index). 2.跳转子组件页面,选择某行数据,点击提交将该行数据传递个父组件 3.父组件取到第一步暂存行号(index),将子组件传 ...

  3. 三,打包electron

    1,在当前项目下运行 npm install --save-dev @electron-forge/cli npx electron-forge import 此时package.json内容如下: ...

  4. PR2022(Premiere Pro 2022)Mac/win最新中文版

    Adobe Premiere Pro 2022 Mac/win是用于专业级别的视频编辑软件,一个基于时间轴的视频处理工具,具有许多用于生成高端视频的不同功能.Adobe Premiere Pro最重要 ...

  5. Java流程控制1

    Scanner对象 java.util.Scanner 通过Scanner类来获取用户输入 next()和nextline()来获取输入的字符串,读取前我们一般需要使用hasnext()和hasnex ...

  6. js实现指定dom节点滚动到可视窗口

    const rollDom = document.getElementById('domId') // 获取想要滚动的dom节点 rollDom.scrollIntoView({ block: 'ce ...

  7. 循环神经网络(Recurrent Neural Networks)(第一部分)

    参考 https://www.cnblogs.com/royhoo/p/Recurrent-Neural-Networks-1.html

  8. PHP中获取时间的下一周下个月的方法

    PHP中获取时间的下一周,下个月等通常用于定制服务的时候使用,比如包月会员,包年等等 //通常用于定制服务的时候使用,比如包月会员,包年等等 //获取当前时间过一个月的时间,以DATETIME格式显示 ...

  9. python开头

    python识别的正则模式 coding[:=]\s*([-\w.]+)#coding:utf8   ???不要用 #coding=utf-8#coding:utf-8# -*- coding: ut ...

  10. mysql修改数据库表及字段的编码格式

    1.修改表的编码格式 ALTER TABLE `table` DEFAULT CHARACTER SET utf8; 2.修改字段编码格式 ALTER TABLE `table` CHANGE `字段 ...