Skip to content

javadoc for HibernateDaoSupport.getHibernateTemplate() could usefully include a reminder about mutating the returned reference [SPR-3204] #7890

@spring-projects-issues

Description

@spring-projects-issues

Jon Seymour opened SPR-3204 and commented

Trivial subclasses of HibernateDaoSupport will normally be thread-safe without explicit programmer effort. However, this relies on the assumption that DAO methods do not modify the HibernateTemplate object returned by HibernateDaoSupport.getHibernateTemplate().

However, a common programming task is to implement finder methods which limit the size of the returned result set. The obvious way to do this is to call the setMaxResults() method on the HibernateTemplate returned by getHibernateTemplate().

Unfortunately, this introduces a thread-safety issue unless precautions are taken to prevent concurrent access to the HibernateTemplate returned from getHibernateTemplate(). Even in the absence of concurrency, a failure by the programmer to restore the original value of setMaxResults() can cause other methods on the same HibernateDaoSupport instance to malfunction due to incorrectly set limits.

It might be helpful if the javadoc for HibernateDaoSupport.getHibernateTemplate() reminded the reader that the returned object should not be modified unless the caller fully understands all the implications of doing so.


Affects: 1.2.8, 2.0.2

Backported to: 1.2.9

1 votes, 0 watchers

Metadata

Metadata

Assignees

Labels

in: dataIssues in data modules (jdbc, orm, oxm, tx)status: backportedAn issue that has been backported to maintenance branchestype: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions