コンポーネント マッピングを使用して、Hibernate 永続オブジェクトのメンバーである不変オブジェクトがあります。例は、PinDropimmutable 型のフィールドを持つテーブルに対応します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がandPointのセッターを持っていないと文句を言うため、これは機能しません。不変オブジェクトを Hibernate 永続オブジェクトのコンポーネントとして使用する方法はありますか?xy
フォローアップ: 私は注釈を使用していませんが、むしろhbm.xml. およびの有効な属性でmutableもありません。immutablecomponentpropertyhbm.xml