我有一个不可变对象,它是使用组件映射的 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没有用于xand的设置器y。有没有办法将不可变对象用作 Hibernate 持久对象的组件?
后续:我没有使用注解,而是hbm.xml. mutable上和中immutable的有效属性都不是。componentpropertyhbm.xml