I'm creating a CompositeUserType
in hibernate to map EAST
and NORTH
fields to a Coordinate object. At present my Coordinate object is immutable, and I'd like to keep it that way if possible.
I've written my nullSafeGet
, pulling the coordinates from the ResultSet and calling the constructor:
@Override
public Object nullSafeGet(ResultSet rs, String[] names,
SessionImplementor session, Object owner)
throws HibernateException, SQLException {
Integer easting = (Integer)Hibernate.INTEGER.nullSafeGet(rs, names[0]);
Integer northing = (Integer)Hibernate.INTEGER.nullSafeGet(rs, names[1]);
if(easting==null || northing==null)
return null;
return new Coordinate(easting, northing);
}
I don't know what to do with setPropertyValue
, which seems to want to set the coords one at a time. It is possible to instantiate an immutable object with CompositeUserType
, or I am trying to do the impossible?
(Also trying to work out what to do about Hibernate.INTEGER being deprecated, but one thing at a time...)
setPropertyValue()
is never called if isMutable()
returns false
, so you can throw UnsupportedOperationException
from it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With