Use of formula in Hibernate configuration file

The formula in the Property element allows object properties to contain derived values, such as the result of sum, average, max, etc. Such as:
<property name= "averagePrice"  formula= "(select avg(pc.price) from PriceCatalogue pc, SelectedItems si where si.priceRefID=pc.priceID)" />  
In addition, formula can also retrieve values ​​from another table based on the value of a specific attribute of the current record. E.g:
code
<property name= "currencyName"  formula= "(select cur.name from currency cur where cur.id= currencyID)" />  
code
<property name= "schNum"  formula= "(select max(a.schoolNumb) from sys_act_code as a)" />  
Notice:
1, formula="()", inside is the sql statement, the field and table name should be corresponding to the database, not the field, if there are parameters such as cur.id= currencyID, this currencyID is the stuff of the object.
2, formula="( sql )", the parentheses cannot be less, otherwise an error will be reported. I have tried several times, and an error will be reported without parentheses.
3, the operation field must use an alias
question:
 1,org.springframework.orm.hibernate3.HibernateSystemException: Null value was assigned to a property of primitive type setter of
If you don't use an alias, this error will occur, just add an alias

2. If I want to use obj.getSchNum() to get the desired value, the object (obj) must be the object obtained by hibernate,

3. If you want to pass in a parameter, such as the one above, currencyID is an attribute of the object, and its value is also automatically passed in when hibernate operates the current object.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327037262&siteId=291194637