Saturday, March 6, 2010

Formula in Map



<key column="ITEM_ID"/>
<map-key type="string" column="IMAGENAME"/>

<property name="filename" column="FILENAME" not-null="true"/>
<property name="sizeX" column="SIZEX"/>
<property name="sizeY" column="SIZEY"/>



This has the drawback that the embedded component class (Image) doesn't have the property imageName which is the map key. It may be undesirable.


<key column="ITEM_ID"/>
<map-key type="string" column="IMAGENAME"/>

<property name="name" type="string" formula="IMAGENAME"/>
<property name="filename" column="FILENAME" not-null="true"/>
<property name="sizeX" column="SIZEX"/>
<property name="sizeY" column="SIZEY"/>



In Hibernate 3.x, formula comes as a rescue here.

[Reference] Hibernate: how to map a collection of embedded components keyed by one of the component's properties?

No comments: