Hi All,
I need some help. We have a
struts app that uses Spring and Hibernate3. When Hibernate does a load() (sql Select) we unencrypt some of the data in the record. As a result, Hibernate suspects the record might be dirty and checks by doing a SQL Update. We don't want this overhead - and also - it's causing hibernate stale object exceptions as we use an optimistic approach - so if one user saves a record while another user is trying to load it the load fails (we handle dirty conditions on the save).
To turn off the update statement calls I set the flush to NEVER on both the session and the hibernate template objects - this works great.
Here's the question:
Since we use Spring we used to call getHibernateTemplate on the Spring HibernateDaoSupport object, but the docs indicate
NOTE: from the
doc on getHibernateTemplate() method -
The returned HibernateTemplate is a shared instance.
You may introspect its configuration, but not modify the
configuration (other than from within an DaoSupport.initDao()
implementation). Consider creating a custom HibernateTemplate
instance via new HibernateTemplate(getSessionFactory()), in which
case you're allowed to customize the settings on the resulting instance.
so now we call
HibernateTemplate lHibernateTemplate = new HibernateTemplate(getSessionFactory());
but this means that for every query we're creating a new HibernateTemplate object that will hang around until the garbage collector runs as opposed to using the shared one --- this application gets hammered on in production so we're concerned about that.
Does anyone have any thoughts about the performance issues of calling new on the HibernateTemplate over and over and over like that? We're not expert Hibernate users so maybe it's a non-issue, but we want to be careful.
Or - any one know of another way to turn off the flushing that causes the sql update right after the sql select ?
Thanks for any feedback,
MM