How can I run a secondary / augmented query in Spring Data JPA to determine calculated value?

StackOverflow https://stackoverflow.com/questions/21487238

  •  05-10-2022
  •  | 
  •  

Question

I am using Spring data 1.4.1 with EclipseLink 1.5.0.

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. I am aware that EclipseLink does not provide similar functionality. We are bound to eclipselink.

I am wondering if Spring Data JPA provides any mechanisms for processing entity information to create and run "additional" queries, if you will. 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?

Était-ce utile?

La solution

I ended up implementing a DescriptorCustomizer. I would prefer an ORM agnostic solution. But for the time being, this solved my issue.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top