org.hibernate.hql.internal.ast.QuerySyntaxException: XXX is not mapped


異常情況:

最近在把一個項目拆分多個 module 的時候數據庫查詢遇到這個異常:org.hibernate.hql.internal.ast.QuerySyntaxException: Identification is not mapped

JPA 查詢方法如下:

public Identification findIdentificationByWxId(String wxId) {
        JPAQueryBase query = new JPAQuery(entityManager).from(qIdentification);
        query.where(qIdentification.wxId.eq(wxId));
        return (Identification) query.fetchOne();
    }

  

異常信息如下:

{
  "timestamp": 1548844710242,
  "status": 500,
  "error": "Internal Server Error",
  "exception": "org.springframework.dao.InvalidDataAccessApiUsageException",
  "message": "org.hibernate.hql.internal.ast.QuerySyntaxException: Identification is not mapped [select identification\nfrom Identification identification\nwhere identification.wxId = ?1];
   nested exception is java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: Identification is not mapped [select identification\nfrom Identification identification\nwhere identification.wxId = ?1]", "path": "/user/getUserInfo" }

  

解決方法:

在springboot 啟動類上加上如下注解便可:
@EntityScan(basePackages = ("cn.xxx.*"))
當一個項目拆分成多個 module 的時候,由於 應用層和實體層已經隔離,所以在應用層啟動應用的時候需要掃描 實體。當然如果應用層需要其他 module 中的配置類的話,也是需要添加掃描配置,掃描到其他 module 中的配置類。如:
@SpringBootApplication(scanBasePackages ="cn.xxx.*")

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM