简体   繁体   English

如何在Spring Data JPA中运行辅助/增强查询以确定计算值?

[英]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.

相关问题 在 Spring 数据 Jpa 中,如何从两个不同的数据源运行 SQL 联合查询...? - In Spring Data Jpa, how can I run an SQL union query from two different datasources...? 如何设置Spring Data JPA查询方法必须始终设置为true的参数值? - How can I set that a Spring Data JPA query method have to be a parameter value always set as true? 如何在 Spring Data jpa 中应用本机连接查询? - How can i apply native join query in spring data jpa? 如何将这3个JOIN查询转换为Spring Data JPA命名查询方法? - How can I convert this 3 JOIN query into a Spring Data JPA named query method? 如何在Spring Data中使用Pageable运行运行时生成的查询? - How can I run a runtime generated query with Pageable in Spring Data? 使用Spring数据Jpa时如何使用大脚本查询数据? - How can I use large a script to query data when using Spring Data Jpa? 如何使用Spring Data MongoDB或Spring Data Jpa - How can I use Spring Data MongoDB or Spring Data Jpa 使用Spring Data JPA,如何创建具有多个条件或在同一字段上或的查询? - Using Spring Data JPA, how can I create a query with multiple conditions ORed on same field? Spring 数据 JPA - 如何使用嵌入式实体进行 existsBy 查询? - Spring Data JPA - How can I make a existsBy query using an embedded entity? 如何使用带有“从方法名创建查询”策略的Spring数据JPA来实现这两个简单查询? - How can I implement these 2 simple queries using Spring data JPA with the “query creation from method names” strategy?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM