aspose file tools*
The moose likes Object Relational Mapping and the fly likes HibernateTemplate help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "HibernateTemplate help" Watch "HibernateTemplate help" New topic
Author

HibernateTemplate help

Mark Manns
Greenhorn

Joined: Jul 06, 2006
Posts: 14
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
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Mark Manns
Greenhorn

Joined: Jul 06, 2006
Posts: 14
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HibernateTemplate help
 
Similar Threads
Hibernate Integration Unit Testing Issues
Transaction failure crashes program
Need some input/tutorial on Hibernate Internals
Spring MVC + Hibernate: Update one column?
How to display DB table values?