![](/img/trans.png)
[英]Update Couchbase documents without overwriting @Created fields with Spring Data Auditing
[英]Spring data couchbase documents java classes inheritance
我的问题是,Spring Data Couchbase不会搜索被搜索类的子类。 例如:
模型:
@Document
class A {
@Id
String id
}
@Document
class B extends A {}
和存储库:
public interface ARepository extends PagingAndSortingRepository<A, String>{
Page<A> findAll(Pageable pageable);
}
Spring Data Couchbase生成查询,条件在何处
_class = “com.example.model.A”
但是我也想在此查询中搜索B文档。 是某种方式,我该怎么做? 当我编写自己的查询时,必须在查询中定义顺序,限制和偏移量,并且不使用Pageable。 但是我想使用Pageable。
考虑基于继承的通用接口。
首先创建超类:
@Inheritance
public abstract class SuperClass{
@Id
private int id;
}
然后创建您的子类:
public class A extends SuperClass { /* ... */ }
public class B extends SuperClass { /* ... */ }
创建基础存储库:
@NoRepositoryBean
public interface SuperClassBaseRepository<T extends SuperClass>
extends PagingAndSortingRepository<T, Integer> {
public T findAll();
}
然后基于基础仓库创建SuperClass存储库:
@Transactional
public interface SuperClassRepository extends SuperClassBaseRepository<SuperClass> { /* ... */ }
@Transactional
public interface ARepository extends SuperClassBaseRepository<A> { /* ... */ }
@Transactional
public interface BRepository extends SuperClassBaseRepository<B> { /* ... */ }
SuperClassRepository findAll()
将搜索所有A和B类
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.