我有一个不可变对象,它是使用组件映射的 Hibernate 持久对象的成员。例如,PinDrop
对应于一个表,该表具有一个不可变类型的字段Point
:
public class PinDrop {
private String name;
private Point location;
// Getters and setters for name and location
}
// Immutable Point
public class Point {
private final double x;
private final double y;
// Getters for x and y, no setters
}
在我的PinDrop.hbm.xml
:
<property name="name" column="name" type="string"/>
<component name="location" class="Point>
<property name="x" column="location_x" type="double"/>
<property name="y" column="location_y" type="double"/>
</component>
这是行不通的,因为在运行时 Hibernate 抱怨Point
没有用于x
and的设置器y
。有没有办法将不可变对象用作 Hibernate 持久对象的组件?
后续:我没有使用注解,而是hbm.xml
. mutable
上和中immutable
的有效属性都不是。component
property
hbm.xml