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. 第08组Beta冲刺(3/4)

    队名 八组评分了吗 组长博客链接(2分) 组员1李昕晖(组长) 过去两天完成了哪些任务 文字/口头描述 了解各个小组的进度与难以攻破的地方,晚上安排开会,安排新的冲刺任务. 重新分配小组及个人任务. ...

  2. 将npm安装镜像切换到淘宝

    cnpm(推荐) 安装 pm install cnpm -g --registry=https://registry.npm.taobao.org 使用 cnpm install [xxxxxxx] ...

  3. SaltStack学习笔记

    SaltStack三大功能: 1. 远程执行 2. 配置管理  (状态) 3.云管理 运维三板斧:监控.执行.配置 四种运行方式: 1.Local 2. Minion/Master   C/S架构 3 ...

  4. homework2软件方法论

    什么是软件工程方法论? 1.软件工程是一个方法论,就是我们在开始一个项目时,大体框架一定要有这么一个概念,而具体实施时,必须根据公司一些特点,优化项目开发的流程,这样才是有实效而方法论只是软件工程的结 ...

  5. Docker-compose安装Wordpress

    Docker-compose实战Wordpress 96 iXiAo9 2019.01.10 18:54 字数 82 阅读 105评论 0喜欢 0 Docker-compose实战Wordpress ...

  6. SpringIOC以及AOP注解开发

    和 XML 配置文件一样,注解本身并不能执行,注解本身仅仅只是做一个标记,具体的功能是框架检测到注解标记的位置,然后针对这个位置按照注解标记的功能来执行具体操作. 本质上:所有一切的操作都是 Java ...

  7. centos 挂载共享目录

    共享目录://10.253.47.102/share/文件传递暂用 将共享路径挂载到centos /etc/fstab  添加一行配置,mount -a 生效

  8. redis 配置哨兵模式时出现的问题(redis 版本 6.2.5)

    今天准备搭建一个 redis 集群(redis 版本 6.2.5),在这之前要先配置好哨兵模式. 但是在配置哨兵模式时出现了问题.之前没有搭建集群时(一主两从,三台虚拟机)可以顺利配置好,而搭建集群时 ...

  9. 利用fread读取二进制文件的bug

    最近在做一个项目时需要读取二进制文件,我用C语言的fread进行读取,代码如下: FILE *fp; int read_data; fopen_s(&fp, file_path, " ...

  10. nRF52832起来之后测试是上电还是休眠唤醒的方法

    void fu_state_machine_init(void) { /* NRF_POWER_RESETREAS_SREQ_MASK JLINK DOWNLOAD / POWER ON can ca ...