Section 13.4. DML-style operations states that
Quote:
As already discussed, automatic and transparent object/relational mapping is concerned with the management of object state. This implies that the object state is available in memory, hence manipulating (using the SQL Data Manipulation Language (DML) statements: INSERT, UPDATE, DELETE) data directly in the database will not affect in-memory state. However, Hibernate provides methods for bulk SQL-style DML statement execution which are performed through the Hibernate Query Language (HQL).
This implies to me that HQL DML-style operations actually affect in-memory states. However, when I run my test code (below), I always see updates against the database, which I was hoping the HQL expression would run against cached entities. This is especially true in that this is NOT a bulk update, but rather updating using the entity's ID. The most important issue to me is that, with it running against the database, I shouldn't have to call refresh on my attached entity.
Could someone clarify this behavior for me?
This code works properly, but removing the refresh causes it to fail.
Code:
Query query = null;
//get record
Map<String,Object> swAssessment = (Map<String,Object>) sessionFactory.getCurrentSession().
load("SwAssessment", "5A3C84EBE05E3530E040007F01000B40");
//Modify fields
swAssessment.put("CGrossCliSs", new Integer(44));
swAssessment.put("CGrossCliRr", new Integer(46));
swAssessment.put("CGrossCliSubt", new Integer(9999));
logger.info("CGrossCliSs:" + swAssessment.get("CGrossCliSs"));
logger.info("CGrossCliRr:" + swAssessment.get("CGrossCliRr"));
logger.info("CGrossCliSubt:" + swAssessment.get("CGrossCliSubt"));
//update via HQL
query = sessionFactory.getCurrentSession().
createQuery("update SwAssessment set " +
"CGrossCliSubt = CGrossCliSs + CGrossCliRr" +
" where guid = :guid").
setString("guid", "5A3C84EBE05E3530E040007F01000B40");
query.executeUpdate();
sessionFactory.getCurrentSession().refresh(swAssessment);
logger.info("CGrossCliSs:" + swAssessment.get("CGrossCliSs"));
logger.info("CGrossCliRr:" + swAssessment.get("CGrossCliRr"));
logger.info("CGrossCliSubt:" + swAssessment.get("CGrossCliSubt"));
//see if record reflects update
assertEquals(new Integer(90), swAssessment.get("CGrossCliSubt"));