• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

HibernateTemplate help

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is the decryption done in Java COde?

You can create another instance variable and just mark it as @Transient. Then have the real instance variable that is mapped to the field to use "property" AccessType. And in the setter method call a method that will set the @Transient value to the decrypted value.

Also, Since you are using Hibernate 3.x, the need for HibernateTemplate is gone. Especially the HibernateDaoSupport class. You are now tightly coupled to Spring by doing that.

As a Spring instructor, the slides even mention it that if you are using Hibernate 3.x, that the HibernateDaoSupport and HibernateTemplates are deprecated.

Mark
 
Mark Manns
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mark

Thank you for the response - sorry it's taken so long to circle back on this. We were still on spring version 1.2.8. I've upgraded to spring 3.0.1 and hibernate 3.3.2.

Can you point me to docs that might help me understand how to replace the HibernateDaoSupport and HibernateTemplate ?

Thanks again,
MM
 
Normally trees don't drive trucks. Does this tiny ad have a license?
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic