Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

alternative of @formula in jpa

Is there any alternative sollution for @formula which is using in hibernate? I need to use it by jpa, for instance:

@Formula("select count(1) from Market m where m.defaultAirportCode=airportCode")
private Boolean isDefault;
like image 491
Marcin Erbel Avatar asked Jun 26 '13 11:06

Marcin Erbel


2 Answers

you can use combination of annotations and one method

@Transient
private Boolean isDefault;

@PostLoad
private void setDefault() {
this.isDefault=this.defaultAirportCode.equals(this.airportCode);
}
like image 64
Bassem Reda Zohdy Avatar answered Oct 13 '22 19:10

Bassem Reda Zohdy


You can use a database view that includes the formula, and map the Entity to the view.

like image 35
James Avatar answered Oct 13 '22 18:10

James