在我的模式中,我有一个表Cutter
,Property
和PropertyValue
。部分列:通过相关属性对Hibernate @OneToMany进行排序?
Cutter
id
Property
id
name
desc
PropertyValue
property_id
cutter_id
value
我想要做的事,如:
@Entity
@Table(name = "Cutter")
public
class
Cutter implements Serializable
{
@OrderBy("property.name asc")
@OneToMany(mappedBy = "cutter") protected SortedSet<PropertyValue> properties;
}
但是,这将导致明显的例外:Unknown column 'properties0_.property.name' in 'order clause'
。
我制作PropertyValue
实施Comparable
,但这似乎不够。无论如何,Hibernate想要注释@OrderBy
。
是'name'属性'PropertyValue'?如果是,只需使用'@OrderBy(“name asc”)' – jorgegm
@jorgegm,抱歉如果不清楚,但不是,'name'是'Property'的属性,这就是为什么这不直截了当。 – Rick
ops,我没有注意到它。根据OrderBy的javadoc,这是不可能的:“属性或字段名称必须与其中的关联类或嵌入类的持久性属性或字段相对应。”一个可行的解决方案是使用'List'并实现'@ PostLoad'方法来构建'SortedSet'。 –
jorgegm