I have been looking a while, but a cannot seem to find any example of a mutable (composite)(user) type, i.e., a type with isMutable() == true.
In particular, I am anxious to find out whether, with such a type, Hibernate can be coerced on object load
not to create a new instance of the mutable type for a particular object property, but to change the existing instance of the mutable type that is the property value.
E.g.
Code:
public class MyClass {
public final java.util.Date importantDate = new java.util.Date();
}
The
MyClass. importantDate property is never
null, but it is
final. Since
Date is mutable, Hibernate could, on load, call
MyClass.importantDate.setTime(long), instead of creating a new
Date instance and try to set the
MyClass.importantDate property with the new instance.
Obviously, there is some kind of type class needed to tell Hibernate that it should use the
setTime(long) (and
getTime()) method to write and read the property. Or is it simply possible to use a
hbm entry that features a path in the property name? Like:
Code:
<property name="importantDate.time"
type="java.util.Date"
update="true"
insert="true"
access="property"
column="importantDate" />
But then still, it would be usefull to have a place where we can state once and for all that, if a property is of type java.util.Date, Hibernate should change the existing object instead of creating a new one.
(Don't focus on the java.util.Date - it is just the mutable type closest at hand).