I have an immutable object that is part of a Hibernate object stored using component mapping. Example: PinDropcorresponds to a table that has an immutable type field Point:
public class PinDrop {
private String name;
private Point location;
}
public class Point {
private final double x;
private final double y;
}
In mine 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>
This does not work, because at runtime, Hibernate complains that it Pointdoes not have setters for xand y. Is there a way to use an immutable object as a component of a Hibernate persistent object?
Follow-up : I do not use annotations, but rather hbm.xml. Neither mutablenor immutableare valid attributes on componentand propertyin hbm.xml.
source