Hi All,
I wonder if components are always seen as immutable objects. I mean...
I have the persistent object (po.User) as declared in the following mapping file. The object has one component (po.UserName).
The problem is that I cannot get the object marked as dirty with the code...
[i]// initialize Session and Transaction
po.User user = ... // user is a persistent object
user.getName().setSurname("change me");
// Is user marked as dirty?
// commit transaction, flush and close Session[/i]
...while it's all right with the code...
[i]// initialize Session and Transaction
po.User user = ... // user is a persistent object
po.UserName newUserName = ... // create a new UserName object
user.setName(newUserName);
// user is marked as dirty
// commit transaction, flush and close Session[/i]
I'm using Hibernate 2.1 . I think the cause of this behaviour (desired or not) is in the class net.sf.hibernate.type.ComponentType
[i]public boolean isDirty(Object x, Object y, SessionImplementor session) throws HibernateException {
if (x==y) return false; // <---------
if (x==null || y==null) return true;
for ( int i=0; i<getters.length; i++ ) {
if ( propertyTypes[i].isDirty( getters[i].get(x), getters[i].get(y), session ) ) return true;
}
return false;
}[/i]
Thanks.
[i]<hibernate-mapping>
<class name="po.User" table="po.User">
<id access="field" name="id" type="string">
<column name="CAT_ID" not-null="true"/>
<generator class="uuid.hex" />
</id>
<version name="version" type="integer" unsaved-value="null"/>
<component name="name" class="po.UserName">
<property access="field" name="title">
<column name="TITLE" not-null="true"/>
</property>
<property access="field" name="name">
<column name="NAME" not-null="true"/>
</property>
<property access="field" name="surname">
<column name="SURNAME" not-null="true"/>
</property>
</component>
...
</class>
</hibernate-mapping>[/i]
|