tags:

views:

21

answers:

1

I would like to add a value object to a mapped class where one column is fixed depending of the class that contains the component. How can I do something like this?

<component name="aComponent">
  <property name="abc" column="cde"/>
  <property name="xyz" value="FIXED"/>
</component>

Unfortunatly, the value attribute does not exist. Is there another way to apply a constant value to property?

Thanks in advance.

+2  A: 

You should use a formula, e.g.

<property name="xyz" formula="1" type="big_decimal"/>

From Java Persistence with Hibernate, ch. 4.4.1:

The given SQL formula is evaluated every time the entity is retrieved from the database (and not at any other time, so the result may be outdated if other properties are modified). The property doesn’t have a column attribute (or subelement) and never appears in an SQL INSERT or UPDATE, only in SELECTs. Formulas may refer to columns of the database table, they can call SQL functions, and they may even include SQL subselects. The SQL expression is passed to the underlying database as is; this is a good chance to bind your mapping file to a particular database product, if you aren’t careful and rely on vendor-specific operators or keywords.

Péter Török