Hibernate version:
2.1.8
Mapping documents:
Code:
<class name="Process" table="workflow_process">
<cache usage="transactional" />
<id name="id" column="id" type="java.lang.Long" unsaved-value="null">
<generator class="increment"/>
</id>
<property name="description" column="description" type="string" />
<property name="state" column="process_state" type="java.lang.Long" />
<property name="status" column="status" type="java.lang.Long" />
<property name="createdBy" column="created_by" type="string" not-null="true" />
<property name="createdOn" column="created_on" type="java.util.Date" not-null="true" />
<many-to-one name="accData" column="acc_id" class="ProcessAccounting" cascade="all"/>
</class>
Code:
<class name="ProcessAccounting" table="workflow_pr_acc" >
<id name="id" column="id" type="java.lang.Long" unsaved-value="null">
<generator class="increment"/>
</id>
<property name="commission" column="commission" type="java.lang.Long"/>
</class>
Code between sessionFactory.openSession() and session.close():map is a Map that contains bean property names mapped to the values of the properties.
process is an instance of Process as per the above mappings
Code:
process.setProperties(map);
process.getAccData().setProperties(map);
The method setProperties is as follows:
Code:
public final void setProperties(Map properties)
{
try
{
PropertyUtils.copyProperties(this, new LazyDynaMap(properties));
}
catch (IllegalAccessException e)
{
e.printStackTrace();
}
catch (InvocationTargetException e)
{
e.printStackTrace();
}
catch (NoSuchMethodException e)
{
e.printStackTrace();
}
}
Full stack trace of any exception that occurs:No exceptions occur but only the top-level object's new values are persisted to the database.
The following
Code:
process.setProperties(myMap);
works fine. The new values are persisted to the DB.
but
Code:
process.getAccountingData().setProperties(myMap);
reports new values in the session cache, but does not persist any changes to the database. For example:
Code:
// we have a processAccounting object of type ProcessAccounting
// the following line reports the old value, which is 10
logger.debug("Commission :: " + processAccounting.getCommission());
Map map = new HashMap();
map.put("commission", new Long(20));
processAccounting.setProperties(map);
session.saveOrUpdate(processAccounting);
// the following line reports the new value, which is 20
logger.debug("Commission :: " + processAccounting.getCommission());
session.flush();
//and the DB still has 10!
Name and version of the database you are using:
MySQL 4.1