zoukankan      html  css  js  c++  java
  • 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
    from Identification identification
    where identification.wxId = ?1];
       nested exception is java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: Identification is not mapped [select identification from Identification identification where identification.wxId = ?1]", "path": "/user/getUserInfo" }

      

    解决方法:

    在springboot 启动类上加上如下注解便可:
    @EntityScan(basePackages = ("cn.xxx.*"))
    当一个项目拆分成多个 module 的时候,由于 应用层和实体层已经隔离,所以在应用层启动应用的时候需要扫描 实体。当然如果应用层需要其他 module 中的配置类的话,也是需要添加扫描配置,扫描到其他 module 中的配置类。如:
    @SpringBootApplication(scanBasePackages ="cn.xxx.*")
    

      

  • 相关阅读:
    Struts2操作request、session和application对象
    json工具性能比较:json-lib和jackson进行Java对象到json字符串序列化[转]
    Java中的内部接口
    Struts2.0 xml文件的配置(package,namespace,action)
    过滤器实用案例
    Struts2教程
    struts全包导入问题
    Maven构建项目速度太慢的解决办法 Maven 调试
    HBase之五:hbase的region分区
    HBase之二:Hbase优化
  • 原文地址:https://www.cnblogs.com/hui-run/p/10339571.html
Copyright © 2011-2022 走看看