Announcement Announcement Module
Collapse
No announcement yet.
Easier way to wrap DAO objects with sessions? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Easier way to wrap DAO objects with sessions?

    When defining beans for my DAO objects, is there an easier way to wrap them in Hibernate sessions than the following? This becomes a bit tedious when you have 100s of classes that will be wrapped with a session:

    Code:
    	<bean id="myUserdataDao" class="app.UserdataVars">
    		<property name="sessionFactory" ref="sessionFactory"/>
    	</bean>	
    
    	<bean id="myUseraccessDao" class="app.UseraccessVars">
    		<property name="sessionFactory" ref="sessionFactory"/>
    	</bean>	
      
    	<bean id="myUsergroupDao" class="app.UsergroupVars">
    		<property name="sessionFactory" ref="sessionFactory"/>
    	</bean>	
      
    	<bean id="myWorkstationDao" class="app.WorkstationVars">
    		<property name="sessionFactory" ref="sessionFactory"/>
    	</bean>

    I've seen something like the following, but cannot get it to work since the "parent" bean has no class type:

    Code:
      <bean id="daoTmpl">
        <property name="sessionFactory">
          <ref bean="sessionFactory"/>
        </property>
      </bean>
    
      <bean id="myObjectDao" class="app.MyObjectDao" parent="daoTmpl"/>
    If the above could be modified to work, that would be ideal. Otherwise, are there any less verbose ways of doing this?

  • #2
    This should work, but I think you just need to mark the parent bean as abstract.
    Code:
      <bean id="daoTmpl" abstract="true">
        <property name="sessionFactory">
          <ref bean="sessionFactory"/>
        </property>
      </bean>
    
      <bean id="myObjectDao" class="app.MyObjectDao" parent="daoTmpl"/>
    Last edited by karldmoore; Aug 29th, 2007, 11:29 AM.

    Comment


    • #3
      Perfect, that did the job, thanks!

      Comment


      • #4
        Originally posted by xaeryan View Post
        Perfect, that did the job, thanks!
        Fantastic, glad that sorted it. This is quite a nice way of reducing the XML, it's good to keep it in mind if you use TransactionProxyFactoryBean.
        Last edited by karldmoore; Aug 29th, 2007, 11:29 AM.

        Comment

        Working...
        X