JPA添加Pageable實(shí)現(xiàn)翻頁(yè)時(shí)報(bào)錯(cuò)的問(wèn)題
JPA添加Pageable實(shí)現(xiàn)翻頁(yè)時(shí)報(bào)錯(cuò)
@Query("from Subject where name like CONCAT('%',:name,'%') and isDelete = 0 order by createTime desc")
Page<Subject> findSubjectByName(@Param("name") String name, Pageable page);
報(bào)錯(cuò):
select count(where) from com.swj.entity.Subject where name like CONCAT('%',:name,'%') and isDelete = 0
添加別名就可以解決
@Query("select t from Subject t where t.name like CONCAT('%',:name,'%') and t.isDelete = 0 order by createTime desc")
Page<Subject> findSubjectByName(@Param("name") String name, Pageable page);
Spring JPA異常的處理
Exception in thread "main" org.springframework.dao.InvalidDataAccessApiUsageException: Unknown entity: com.ecs.model.User; nested exception is java.lang.IllegalArgumentException: Unknown entity: com.ecs.model.User
at org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:381)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:418)
at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:58)
at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:213)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:163)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
at com.sun.proxy.$Proxy14.save(Unknown Source)
at ecs.Test1.main(Test1.java:43)
Caused by: java.lang.IllegalArgumentException: Unknown entity: com.ecs.model.User
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:878)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:291)
at com.sun.proxy.$Proxy13.persist(Unknown Source)
at com.ecs.dao.UserDaoImpl.save(UserDaoImpl.java:19)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:155)
... 6 more
解決方法
把persistence.xml放在src下的META-INF文件中
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
springboot優(yōu)雅獲取前端參數(shù)的方法詳解
現(xiàn)在的項(xiàng)目基本上都是前后端分離的項(xiàng)目,如何打通前后端,接收前端傳過(guò)來(lái)的參數(shù)呢,這篇文章小編就來(lái)和大家詳細(xì)介紹一下springboot如何優(yōu)雅的獲取前端參數(shù)吧2024-03-03
Spring?零基礎(chǔ)入門(mén)WebFlux框架體系
Spring5發(fā)布有兩年了,隨Spring5一起發(fā)布了一個(gè)和Spring?WebMvc同級(jí)的Spring?WebFlux。這是一個(gè)支持反應(yīng)式編程模型的新框架體系。反應(yīng)式模型區(qū)別于傳統(tǒng)的MVC最大的不同是異步的、事件驅(qū)動(dòng)的、非阻塞的,這使得應(yīng)用程序的并發(fā)性能會(huì)大大提高,單位時(shí)間能夠處理更多的請(qǐng)求2022-07-07
java.io.EOFException產(chǎn)生原因及解決方法(附代碼)
java.io.EOFException表示在讀取數(shù)據(jù)時(shí)突然遇到了文件或流的末尾,也就是說(shuō)客戶端或服務(wù)器已經(jīng)關(guān)閉了連接,但是你還在嘗試讀取數(shù)據(jù),這篇文章主要給大家介紹了關(guān)于java.io.EOFException產(chǎn)生原因及解決的相關(guān)資料,需要的朋友可以參考下2023-09-09
springboot后端存儲(chǔ)富文本內(nèi)容的思路與步驟(含圖片內(nèi)容)
在所有的編輯器中,大概最受歡迎的就是富文本編輯器和MarkDown編輯器了,下面這篇文章主要給大家介紹了關(guān)于springboot后端存儲(chǔ)富文本內(nèi)容的思路與步驟的相關(guān)資料,需要的朋友可以參考下2023-04-04
Java長(zhǎng)度不足左位補(bǔ)0的3種實(shí)現(xiàn)方法
這篇文章主要介紹了Java長(zhǎng)度不足左位補(bǔ)0的3種實(shí)現(xiàn)方法小結(jié),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-12-12
Java使用Filter實(shí)現(xiàn)登錄驗(yàn)證
本文主要介紹了Java使用Filter實(shí)現(xiàn)登錄驗(yàn)證,Filter類(lèi)似于門(mén)衛(wèi),你在進(jìn)入之前門(mén)衛(wèi)需要盤(pán)查你,身份合法進(jìn)入,身份不合法攔截,感興趣的可以了解一下2023-11-11
淺談SpringCloud?Alibaba和SpringCloud的區(qū)別
這篇文章主要介紹了淺談SpringCloud?Alibaba和SpringCloud的區(qū)別,Spring?Cloud?Netflix框架也屬于Spring?Cloud,但是Netflix并不是由spring來(lái)進(jìn)行開(kāi)發(fā)的,需要的朋友可以參考下2023-05-05
java后臺(tái)如何利用Pattern提取所需字符詳解
這篇文章主要給大家介紹了關(guān)于java后臺(tái)如何利用Pattern提取所需字符的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2022-01-01

