最近在把一个项目拆分多个 module 的时候数据库查询遇到这个异常:org.hibernate.hql.internal.ast.QuerySyntaxException: Identification is not mappedjava
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.*")