Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Tommy
Tommy

Posted on

     

Hibernate - @Formula

Formula Annotation

The @Formula annotation is used to calculate the dynamic value of a property. @Formula takes an expression (this could be simple expression or a complex query) as a parameter. During fetch time, it evaluates the expression and assigns the evaluated value to the property.

Examples

// ex 1@Formula("lower(datediff(curdate(), birth_date / 365)")private int age;// ex 2@Formula("(select min(s.survey) from statistics s) ")private float total;// ex 3private int num1;private int num2;private int num3;@Formula(" num1 + num2 + num3")private float totalSum;
Enter fullscreen modeExit fullscreen mode

Note:
-This is only inserted in a SELECT clause!
-Be careful when using this because the SQL command you may be using may be vendor specific. In other words, this will create coupling with a particular SQL vendor.

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

I am a full-stack developer specializing in web 🌐 and mobile 📱 apps.
  • Location
    USA
  • Education
    AB IT, MSc IT
  • Joined

More fromTommy

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp