Results 1 to 4 of 4

Thread: Easier way to wrap DAO objects with sessions?

  1. #1

    Default 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. #2
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    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 at 11:29 AM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

  3. #3

    Default

    Perfect, that did the job, thanks!

  4. #4
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Quote 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 at 11:29 AM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •