如何在Spring Boot JPA中将实体名称作为变量提供给查询

Roh*_*eja 1 hibernate spring-data-jpa spring-boot

@Query("select c from :entity c )

BaseEntity findOne( @Param("value") String entity );
Run Code Online (Sandbox Code Playgroud)

这给出了一个错误说:

由以下原因引起:org.hibernate.hql.internal.ast.QuerySyntaxException:意外令牌::靠近第1行,第15列[从:entity c中选择c],位于org.hibernate.hql.internal.ast.QuerySyntaxException.convert(QuerySyntaxException。 java:91)〜[hibernate-core-4.3.11.Final.jar:4.3.11.Final]

pat*_*s91 5

http://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.query.spel-expressions

有您的答案,包括一个示例。

编辑:这不是您所要求的100%,但这是在@Query中操作实体的唯一可能方式。