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.*")
    

      

  • 相关阅读:
    Ubuntu 12.10使用apt安装Oracle/Sun JDK
    织梦(dedecms)系统常用全局变量调用标签及路径
    Lighttpd虚拟主机和多域名的配置
    Ubuntu解压命令大全
    OFBiz终于起航了
    eclipse 安装gradle 插件的三种方式
    验证码
    session的使用
    实验二
    作业2(魔术)
  • 原文地址:https://www.cnblogs.com/hui-run/p/10339571.html
Copyright © 2011-2022 走看看