[英]How can I run a secondary / augmented query in Spring Data JPA to determine calculated value?
I am using Spring data 1.4.1 with EclipseLink 1.5.0. 我在EclipseLink 1.5.0中使用Spring数据1.4.1。
I have an entity as such: 我有这样一个实体:
@Entity
public class A {
// ... other fields ...
@Transient
private boolean calculatedField;
}
I ideally want to populate the calculated field on post load. 理想情况下,我想在加载后填充计算字段。 The value logically is a rather complicated query.
从逻辑上讲,该值是一个相当复杂的查询。 In Hibernate, you can annotate the field with @Formula.
在Hibernate中,您可以使用@Formula注释字段。 I am aware that EclipseLink does not provide similar functionality.
我知道EclipseLink不提供类似的功能。 We are bound to eclipselink.
我们一定要使用eclipselink。
I am wondering if Spring Data JPA provides any mechanisms for processing entity information to create and run "additional" queries, if you will. 我想知道,如果您愿意,Spring Data JPA是否提供任何机制来处理实体信息以创建和运行“其他”查询。 Or to augment the original query?
还是增加原始查询?
My first thought would be to implement the Repository and simply set the field in a secondary query. 我的第一个想法是实现存储库,并在辅助查询中简单地设置字段。 I'd rather avoid concrete implementations of the repository if I could.
如果可以的话,我宁愿避免存储库的具体实现。
Suggestions? 有什么建议吗?
I ended up implementing a DescriptorCustomizer . 我最终实现了DescriptorCustomizer 。 I would prefer an ORM agnostic solution.
我希望使用ORM不可知的解决方案。 But for the time being, this solved my issue.
但是暂时,这解决了我的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.