JPA不忽略自定义功能
我正在使用: spring-boot-starter-data-jpa v2.5.12。 spring-boot:v2.5.12
我有以下存储库:
@RepositoryRestResource(collectionResourceRel = "flow", path = "flow")
public interface FlowRepository extends
PagingAndSortingRepository<Flow, String>,
NativeSqlRepository
在 NativeSqlRepository 中,我有一个自定义函数。
public interface NativeSqlRepository {
List<HashMap<String, Object>> querySelect(String query, Object... parameters);
}
以及 NativeSqlRepositoryImpl 中此函数的实现 我不希望 Spring Data JPA 根据函数名称生成查询。
我收到以下错误:
Caused by: org.springframework.data.repository.query.QueryCreationException:
Could not create query for public abstract java.util.List com.ge.predix.cyber.util.database.NativeSqlRepository.querySelect(java.lang.String,java.lang.Object[])!
Reason: Failed to create query for method public abstract java.util.List com.ge.predix.cyber.util.database.NativeSqlRepository.querySelect(java.lang.String,java.lang.Object[])!
No property querySelect found for type Flow!;
nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract java.util.List com.ge.predix.cyber.util.database.NativeSqlRepository.querySelect(java.lang.String,java.lang.Object[])!
No property querySelect found for type Flow!
Im using:
spring-boot-starter-data-jpa v2.5.12.
spring-boot: v2.5.12
I have the following repository:
@RepositoryRestResource(collectionResourceRel = "flow", path = "flow")
public interface FlowRepository extends
PagingAndSortingRepository<Flow, String>,
NativeSqlRepository
In the NativeSqlRepository, I have a custom function.
public interface NativeSqlRepository {
List<HashMap<String, Object>> querySelect(String query, Object... parameters);
}
and an implementation for this function in NativeSqlRepositoryImpl
I don't want Spring Data JPA to generate queries based on the function name.
I'm getting the follow error:
Caused by: org.springframework.data.repository.query.QueryCreationException:
Could not create query for public abstract java.util.List com.ge.predix.cyber.util.database.NativeSqlRepository.querySelect(java.lang.String,java.lang.Object[])!
Reason: Failed to create query for method public abstract java.util.List com.ge.predix.cyber.util.database.NativeSqlRepository.querySelect(java.lang.String,java.lang.Object[])!
No property querySelect found for type Flow!;
nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract java.util.List com.ge.predix.cyber.util.database.NativeSqlRepository.querySelect(java.lang.String,java.lang.Object[])!
No property querySelect found for type Flow!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯,代码很好。
问题是存储库位于不同的类路径上。
因此,我需要在 JPA 存储库中指定它。
Well the code was fine.
The problem was the the repository is found on a different class path.
So, I needed to specify it in the JPA repositories.