我有一個不可變的對象,它是使用組件映射的Hibernate持久對象的成員。例如,PinDrop
對應一個表,其中有一個類型不變Point
的領域:不可變對象的Hibernate組件映射
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>
這並不是因爲在運行時休眠工作抱怨說Point
不有x
和y
的安裝者。有沒有辦法將不可變對象用作Hibernate持久對象的組件?
後續行動:我沒有使用註釋,而是使用了hbm.xml
。 mutable
和immutable
均不在component
和property
的hbm.xml
的有效屬性。
你需要使字段「最終」? – 2013-03-21 22:36:08