我有一个场地映射类,如:
<class name="Venue">
<id name="venueId">
<generator class="identity"/>
</id>
<natural-id>
<property name="name"/>
<property name="countryISO2"/>
</natural-id>
<property name="name"/>
<property name="locale"/>
<component name="location">
<property name="countryISO2"/>
<property name="city"/>
</component>
</class>
问题是来自name="countryISO2"
标记的natural-id
属性无法以这种方式识别。我也试过了name="location.countryISO2"
这也不起作用。
有人可以建议如何解决这个问题吗?
更新:
例外是:
Caused by: org.hibernate.PropertyNotFoundException: field [countryISO2] not foun
d on nl.texxi.oct.model.Venue
at org.hibernate.property.DirectPropertyAccessor.getField(DirectProperty
Accessor.java:182)
at org.hibernate.property.DirectPropertyAccessor.getField(DirectProperty
场地类是:
public class Venue {
private int venueId;
private String name;
private Locale locale;
private Location location;
// getters and setters
}
当然还有Location
类,其中包含countryISO2
,city
等字段。
在数据库中,venue
表包含:venueId, name, locale, countryIso2, city
所以基本上位置只是域模型上某些字段的组合。
答案 0 :(得分:1)
根据休眠DTD,这应该可以解决您的问题
<natural-id>
<component name="location">
<property name="countryISO2"/>
<property name="city"/>
</component>
</natural-id>
你应该删除映射底部的<component>
。