自提出问题以来的更新
问题由PR确定:
https://github.com/spring-projects/spring-data-jpa/pull/283
描述
我已经配置了spring-boot + spring-data-jpa项目。我的存储库有下一个自定义查询:
@Repository
public interface MyEntityRepository extends JpaRepository<MyEntity, String>, QueryDslPredicateExecutor<MyEntity> {
...
@Query(
value = " SELECT me.name FROM #{#entityName} me ",
countQuery = " SELECT COUNT(me.name) FROM MyEntity me "
)
Page<String> findAllMyEntityNames(final Predicate predicate, final Pageable pageable);
...
}
这很好用。但对于我来说,最好在查询和countQuery中使用#{#entityName}
无处不在,即:
countQuery = " SELECT COUNT(me.name) FROM #{#entityName} me "
所以,我的问题:
ps:如果我在countQuery中使用#{#entityName}
,则会发生下一个异常:
...
Caused by: java.lang.IllegalArgumentException: org.hibernate.QueryException: unexpected char: '#' [ SELECT COUNT(me.name) FROM #{#entityName} me ]
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1679) ~[hibernate-entitymanager-5.0.11.Final.jar:5.0.11.Final]
...
Caused by: org.hibernate.QueryException: unexpected char: '#' [ SELECT COUNT(me.name) FROM #{#entityName} me ]
...
由于
此致 马克西姆