[hibernate-dev] Modeling natural-id on entity in XML
Hardy Ferentschik
hardy at hibernate.org
Tue Feb 18 06:17:46 EST 2014
On 18 Jan 2014, at 08:32, Steve Ebersole <steve at hibernate.org> wrote:
> As we move to 5.0 and the new unified XML format I'd like to revisit the
> ways we have mapped certain things historically in hbm.xml and improve upon
> them when possible. At the moment I am looking at mapping of natural ids.
> In hbm.xml the form was to wrap the attributes making up the natural id in
> a grouping:
>
> <class name="Person">
> <id name="id"/>
>
> <natural-id>
> <property name="lastName"/>
> <property name="firstName"/>
> </natural-id>
>
> ...
> </class>
in the context of adding cache config aspects I think I prefer this version.
It groups the properties and more importantly allows to specify the mutability and
cache settings on the enclosing node:
<class name="Person">
<id name="id"/>
<natural-id mutable="true|false" cache-region="ABC">
<property name="lastName"/>
<property name="firstName"/>
</natural-id>
...
</class>
This is imo more intuitive then:
...
<natural-id mutable="true|false" cache-region="ABC" />
<basic name="lastName" natural-id="true" />
<basic name="firstName" natural-id="true" />
...
> which can become unwieldy if you want these values to exist in other
> groupings.
Are there many potential other groups? If it is a rare case, why not just letting
the user repeat the properties per group?
—Hardy
More information about the hibernate-dev
mailing list