当前位置:网站首页>记录一下使用JPA时遇到的坑
记录一下使用JPA时遇到的坑
2022-06-12 11:08:00 【YOSHINO_Cream】
前言
这几天做实习任务,发下来的项目ORM框架使用的是JPA,之前完全没有接触过,不过也能照葫芦画瓢写一下,这过程中碰到了一点坑,特此记录一下,后期如果再碰到还会继续更新。
环境
项目比较老 Spring-boot版本是1.5.6对应的spring-boot-jpa版本也是1.5.6.RELEASE
坑1
该方法传了两个参数 都是String 然后运行时报错
JPA-style positional param was not an integral ordinal;
说是没有按照顺序使用JPA风格的参数
SQL部分语句是这样的
如图所使,在箭头指向的方向传了参数,这样会报错。之后上网上查了查,有人说是参数后面必须跟一个空格,否则会不被识别。照做了之后能够正常运行。
正确写法如上
坑2
** You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near **
相同的SQL语句,直接扔数据库进行查询能够正常通过,但通过JPA进行查询就会报这个错误。
我观察了一下这个SQL语句,发现where关键字没有像其他关键字一样用黄色来凸显出来。推测又是空格的原因 于是在前面加了个空格
这下能够被识别出来了,进行测试,正常通过了。
总结
其实踩到这两个坑归根揭底都是SQL解析的问题,当不加空格时,在进行SQL解析时会把关键字和别的字段连一块解析,而长sql导致了我们很难在第一时间发现这个问题。总之尽量少写长SQL
边栏推荐
- The difference between meta universe chain games and traditional games
- 读mysql45讲-自我总结(部分)
- ReentrantLock源码分析
- 淺談調和形狀上下文特征HSC對3DSC的改進
- k53.第二章 基于二进制包安装kubernetes v1.22 --集群部署
- Amélioration de la 3dsc par HSC
- Clickhouse column basic data type description
- PHP specifies the number of people to distribute the specified amount equally at random (scaling method)
- Flex layout
- ^33 variable promotion and function promotion interview questions
猜你喜欢
随机推荐
PHP string encryption and decryption
890. 查找和替换模式
Common configuration commands for Cisco network device security management
Leetcdoe 2037. Make each student have the minimum number of seat movements (yes, once)
Common methods of string class
AcWing 1995. 见面与问候(模拟)
Verifiability and scarcity of NFT Digital Collections
元宇宙链游与传统游戏的区别
Pseudo static setting of access database in win2008 R2 iis7.5
AcWing 41. 包含min函数的栈(单调栈)
【clickhouse专栏】基础数据类型说明
Principle analysis of vite HMR
PHP uses leanclound to save associated properties
MYSQL——内置函数
k58.第一章 基于kubeadm安装kubernetes v1.23 -- 集群部署
AcWing 1921. Rearranging cows (ring diagram)
(三十七)Bee如何同时使用不同数据源实例
【clickhouse专栏】基础数据类型说明
Reading mysql45 lecture - self summary (part)
The solution of Lenovo notebook ThinkPad t440 WiFi dropping all the time








