Announcement Announcement Module
Collapse
No announcement yet.
Notion of "singleton" attribute with EJB access Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Notion of "singleton" attribute with EJB access

    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:

    Code:
       
    <bean id="clmClaimDaoTarget" singleton="false"    class="com.mitchell.services.technical.claim.dao.spring.ClmClaimHibernateDao">
          <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.ClmClaimDao</value>
          </property>
          <property name="interceptorNames">
             <list>
                <value>myHibernateInterceptor</value>
                <value>clmClaimDaoTarget</value>
             </list>
          </property>
       </bean>
    Thanks,
    Lou

  • #2
    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,

    Comment


    • #3
      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

      Comment


      • #4
        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,

        Comment

        Working...
        X