[英]@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.