ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chris Lamey" <cla...@localmatters.com>
Subject RE: Spring and Ibatis DAOs, Singleton vs Prototypes
Date Fri, 04 Aug 2006 17:38:14 GMT
Hello,

I've got all my DAOs and my Spring sqlMapClient defined as singletons in my app context without
any problems at all.  I keep my DAOs stateless, so everything's on its own Thread stack and
not a big deal...and the sqlMapClient uses ThreadLocals so one instance can be shared by different
Threads.  I haven't looked at the sqlMapClient code closely, but I'd guess you'd hit db limits
before you'd hit any kind of context switching issues in Java.

By default beans defined in an app context are singletons, which is what all the examples
and posts in the Spring world I've seen use for iBATIS.

Cheers,
Chris

-----Original Message-----
From: Mississippi John Hurt [mailto:johnhurt@gmail.com]
Sent: Fri 8/4/2006 11:27 AM
To: user-java@ibatis.apache.org
Subject: Spring and Ibatis DAOs, Singleton vs Prototypes
 
Hi,
I'm wondering is it safe to have ibatis DAOs instantiated in spring
framework as singletons?  Say you have a DAO like below. How do most of you
who work with high-volume real-life apps instantiate DAOs like the below, as
singleton or prototype?

public class ObjectDaoIbatis  {
    public Object getObject(Long userId) {
        Object object = (Object)
getSqlMapClientTemplate().queryForObject("getObject", objectId);

        if (object == null) {
            logger.warn("error");
            throw new Exception(); }
        return object;
    }
}


Mime
View raw message