- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我发现 QueryDslPredicateExecutor 对于减少样板文件非常有用,但它似乎给工作带来了麻烦。我现在尝试使用自定义基类存储库扩展 JpaRepository
,但在启动时,Spring 无法正确实例化存储库。
//Custom base class
@NoRepositoryBean
public interface IdAwareRepository<A, ID extends Serializable> extends JpaRepository<A, ID> {
// ID getId(A a);
}
// Base class implementation
public class IdAwareRepositoryImpl<A, ID extends Serializable>
extends SimpleJpaRepository<A, ID> implements IdAwareRepository<A, ID> {
public IdAwareRepositoryImpl(JpaEntityInformation<A, ?> entityInformation, EntityManager entityManager) {
super(entityInformation, entityManager);
}
}
// Individual repo
@Repository
public interface MyPojoRepository extends JpaRepository<MyPojo, Integer>, QueryDslPredicateExecutor<MyPojo> {
}
// Spring boot main application class
@EnableJpaRepositories(repositoryBaseClass = IdAwareRepositoryImpl.class)
@EntityScan(basePackageClasses = {Application.class, Jsr310JpaConverters.class})
@EnableAutoConfiguration(exclude = {
org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration.class,
org.springframework.boot.actuate.autoconfigure.ManagementWebSecurityAutoConfiguration.class})
@SpringBootApplication
public class Application {}
我已经尝试过这个主题的几种变体,但没有成功地连接起来。我在 Spring 的问题跟踪器 https://jira.spring.io/browse/DATAJPA-674 上遇到了类似的问题,但没有对修复进行解释,只是代码被重构以使其更易于使用。
我收到以下错误:
Caused by: org.springframework.data.mapping.PropertyReferenceException: No property findAll found for type MyPojo! at org.springframework.data.mapping.PropertyPath.(PropertyPath.java:77) at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:329) at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:309) at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:272) at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:243) at org.springframework.data.repository.query.parser.Part.(Part.java:76) at org.springframework.data.repository.query.parser.PartTree$OrPart.(PartTree.java:235) at org.springframework.data.repository.query.parser.PartTree$Predicate.buildTree(PartTree.java:373) at org.springframework.data.repository.query.parser.PartTree$Predicate.(PartTree.java:353) at org.springframework.data.repository.query.parser.PartTree.(PartTree.java:84) at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.(PartTreeJpaQuery.java:62) at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:100) at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:211) at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:74) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.(RepositoryFactorySupport.java:416) at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:206) at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:251) at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:237) at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:92) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
对我来说,Spring 无法将自定义基类和 QueryDslPredicateExecutor
扩展连接到 JpaRepository
最佳答案
我通过让我的基础存储库扩展 QueryDslMongoRepository 解决了类似的问题。
您也许能够扩展类似的类。
关于java - 自定义存储库基类 + QueryDslPredicateExecutor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36293960/
我发现 QueryDslPredicateExecutor 对于减少样板文件非常有用,但它似乎给工作带来了麻烦。我现在尝试使用自定义基类存储库扩展 JpaRepository,但在启动时,Spring
当我尝试使用 Querydsl 时,如 Spring 引用 Spring 1.10.4.RELEASE reference 中所示- 我从 IDE 收到一些错误: 无法解析方法 findAll(pre
我尝试按照Spring Data JPA with QueryDSL中的教程进行操作 我的代码版本如下: spring-boot = 1.3.8.release 查询 dsl = 3.7.4 我的实体
我有一个基于 Spring Data 和 JPA QueryDSL 的项目,其中我有许多扩展 QueryDslPredicateExecutor 的存储库接口(interface),如下所示: pub
我有一个实体如下: @Entity public class Enterprise{ private String sid = UUID.randomUUID().toString(); pr
假设我有一个这样的数据模型(伪代码): @Entity Person { @OneToMany List attributes; } @Entity PersonAttribute {
我正在 Spring Data Rest 之上构建 REST API。最初扩展 JpaRepository 的所有存储库。最近决定采取更灵活的方法并使用 QueryDslPredicateExecut
我正在使用下面的代码使用存储库从 mongo 获取数据: BooleanBuilder booleanBuilder = new BooleanBuilder(); booleanBuilder
我被这个错误困住了: 我想使用一种方法,通过 QueryDslPredicateExecutor 对谓词进行搜索。当该方法在我的服务实现上运行时,出现此错误: 16:59:44,165 DEBUG [
我花了几个小时在 spring 数据中找到 QueryDslPredicateExecutor。为什么叫它QueryDslPredicateExecutor 在文档和博客中,但 QuerydslPre
我正在尝试将 QueryDslPredicateExecutor 与 MongoDB 和 Spring-Data 一起使用,但它似乎对“exists()”属性感到窒息。 我正在使用 - org.spr
我是一名优秀的程序员,十分优秀!