Hibernate CompositeUserType for immutable object

I create in hibernate to map the EAST and NORTH fields for a Coordinate object. Currently, my Coordinate object is immutable, and I would like to save it this way if possible.

I wrote 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 coords one at a time. Can I instantiate an immutable object using CompositeUserType , or am I trying to do the impossible?

(Also trying to figure out what to do with Hibernate.INTEGER, deprecated, but one at a time ...)

+8
java hibernate
source share
1 answer

setPropertyValue() never called if isMutable() returns false , so you can throw an UnsupportedOperationException from it.

+11
source share

All Articles