简体   繁体   English

@Query引起者:org.hibernate.hql.internal.ast.QuerySyntaxException:主题未映射错误

[英]@Query Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: topic is not mapped error

@Repository
public interface TopicRepository extends CrudRepository<Topic, String>{ 
    @Query(value = "SELECT u from topic u where u.name = ?1")
    List<Topic> findEverything(String name);
}

According to the spring documentation, I can do the above @query. 根据spring文档,我可以执行上述@query。 However, it gives me Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: topic is not mapped error. 但是,它给我的原因是:org.hibernate.hql.internal.ast.QuerySyntaxException:主题未映射错误。

However, when i do this below, it works. 但是,当我在下面执行此操作时,它将起作用。

@Repository
public interface TopicRepository extends CrudRepository<Topic, String>{
    @Query(value="SELECT * FROM topic WHERE topic.name = ?1", nativeQuery = true)
    List<Topic> findEverything(String name);
}

I am using mySQL database. 我正在使用mySQL数据库。 I need to know why. 我要知道为什么 please help me thank you. 请帮我谢谢。

if you're using a JPQL query, try to annotate and name your param, instead of relying on positional params, like so: 如果您使用的是JPQL查询,请尝试注释和命名您的参数,而不要依赖位置参数,例如:

@Query(value = "SELECT u from topic u where u.name = :name")
List<Topic> findEverything(@Param("name")String name);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:org.hibernate.hql.internal.ast.QuerySyntaxException:网站未映射 - Error:org.hibernate.hql.internal.ast.QuerySyntaxException: Website is not mapped Hibernate-org.hibernate.hql.internal.ast.QuerySyntaxException:未映射客户端 - Hibernate - org.hibernate.hql.internal.ast.QuerySyntaxException: Client is not mapped 休眠 5 org.hibernate.hql.internal.ast.QuerySyntaxException:Emplooye 未映射 - hibernate 5 org.hibernate.hql.internal.ast.QuerySyntaxException: Emplooye is not mapped IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: ClassName 未映射 - IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: ClassName is not mapped org.hibernate.hql.internal.ast.QuerySyntaxException:未映射[来自Team] - org.hibernate.hql.internal.ast.QuerySyntaxException: is not mapped [from Team] org.hibernate.hql.internal.ast.QuerySyntaxException:员工未映射 - org.hibernate.hql.internal.ast.QuerySyntaxException: Employee is not mapped org.hibernate.hql.internal.ast.QuerySyntaxException:报告表未映射 - org.hibernate.hql.internal.ast.QuerySyntaxException: REPORT Table is not mapped org.hibernate.hql.internal.ast.QuerySyntaxException:InspectionRequestEntity 未映射 - org.hibernate.hql.internal.ast.QuerySyntaxException: InspectionRequestEntity is not mapped org.hibernate.hql.internal.ast.QuerySyntaxException:未映射产品 - org.hibernate.hql.internal.ast.QuerySyntaxException: Product is not mapped org.hibernate.hql.internal.ast.QuerySyntaxException:实体未映射 - org.hibernate.hql.internal.ast.QuerySyntaxException: Entity is not mapped
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM