Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate: Use HQL inside @Formula annotation?

From what I've been testing it seems that you can only use standard SQL inside a @Formula annotation. The documentation is not very descriptive about this feature (I've found one paragraph about it at most), so I was wondering whether HQL can be used somehow or whether there's another feature that would let me load an object's property with a HQL query.

like image 416
JayPea Avatar asked May 14 '12 17:05

JayPea


Video Answer


1 Answers

You are right . @Formula only allows to use the actual column name .

The important characteristic of HQL is use the java property name to refer the actual column name . If you want to refer the property names when deriving your formula value , you can simply implement the logic of the formula in the getter of your mapped POJOs.

like image 151
Ken Chan Avatar answered Oct 13 '22 00:10

Ken Chan