PDA

View Full Version : Notion of "singleton" attribute with EJB access


Loumeister
Aug 18th, 2004, 01:33 AM
I've been wondering what's the best practice around using the singleton attribute on DAOs defined in the applicationContext. These DAO's are being accessing by EJBs, so I have been setting them to false.

I've been setting it as such on the interface DAO, but not sure if I should set on the implementation DAO bean that attaches my interceptors. Here's an example:


<bean id="clmClaimDaoTarget" singleton="false" class="com.mitchell.services.technical.claim.dao.spring.C lmClaimHibernateDao">
<property name="sessionFactory">
<ref local="mySessionFactory"/>
</property>
</bean>
<bean id="clmClaimDao"
class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="proxyInterfaces">
<value>com.mitchell.services.technical.claim.dao.ClmClaim Dao</value>
</property>
<property name="interceptorNames">
<list>
<value>myHibernateInterceptor</value>
<value>clmClaimDaoTarget</value>
</list>
</property>
</bean>

Thanks,
Lou

Colin Sampaleanu
Aug 18th, 2004, 03:02 PM
DAOs can almost always be singletons, and whether they are being accessed by EJBs or another client should not really affect this in a significant way. I'm confused as to why you think you need to make them singleton.

Regards,

Loumeister
Aug 19th, 2004, 03:18 AM
It's not that I want to make them singletons, it's more a question of which bean I should use "singleton=false" on; the interface (the target) or the implementation or both. Right now I'm just doing it on the target. Better question might be what's the default for singleton attribute (this might be moot)?

My reason for not having them as singletons is because of the whole EJB/singleton issue being in a distributed environment with mutliple classloaders/JVM. I don't necessarily know what server I may be on one minute to the next if they're clustered.

Best,
Lou

Colin Sampaleanu
Aug 19th, 2004, 11:39 AM
Singleton="true" is default on beans in the beanfactory, as described in the manual and DTD.

Even if the proxy is a singleton, you're still going through the AppServer's stub on each invocation, so you will be able to handle going out to another cluster member and the like. So you can leave everything as singleton...

Regards,