JPA不忽略自定义功能

发布于 2025-01-19 05:37:52 字数 1363 浏览 0 评论 0原文

我正在使用: 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

平生欢 2025-01-26 05:37:52

嗯,代码很好。
问题是存储库位于不同的类路径上。
因此,我需要在 JPA 存储库中指定它。

@EnableJpaRepositories({"com.cyber.util.database","com.message.tracing.repository"})
public class Application {...}

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.

@EnableJpaRepositories({"com.cyber.util.database","com.message.tracing.repository"})
public class Application {...}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文