Formula in Hibernate

By: Dorris  

Sometimes, you want the Database to do some computation for you rather than in the JVM, you might also create some kind of virtual column. You can use a SQL fragment (aka formula) instead of mapping a property into a column. This kind of property is read only (its value is calculated by your formula fragment).

@Formula("obj_length * obj_height * obj_width") public long getObjectVolume()

The SQL fragment can be as complex as you want and even include subselects.

Archived Comments

Most Viewed Articles (in Hibernate )

Latest Articles (in Hibernate)

Comment on this tutorial