【发布时间】:2013-03-22 07:36:32
【问题描述】:
我有一个不可变对象,它是使用组件映射的 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 和 y 的设置器。有没有办法将不可变对象用作 Hibernate 持久对象的组件?
跟进:我没有使用注解,而是hbm.xml。 mutable 和 immutable 都不是 component 和 property 在 hbm.xml 中的有效属性。
【问题讨论】: