Announcement Announcement Module
Collapse
No announcement yet.
Application context problem Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Application context problem

    Hello

    I jsut start to use Spring and i am a little lost so if yuo could help me i would be very pleased.

    My problem is that how i config my application context that i could create a upper class on Dao level.

    Right now my application context look like this:

    <!-- DAO Definition: Hibernate implementation -->
    <bean id="customerDao" class="CustomerDaoHibernateImpl">
    <property name="hibernateTemplate"><ref bean="hibernateTemplate"/></property>
    </bean>

    <!-- QueryTool object: Hibernate implementation -->
    <bean id="hibernateQueryTool" class="HibernateQueryTool">
    <property name="hibernateTemplate"><ref bean="hibernateTemplate"/></property>
    </bean>

    <!-- Service Defintion -->
    <bean id="CustomerService" class="CustomerServiceImpl">
    <property name="customerDao"><ref local="customerDao"/></property>
    </bean>

    I want to do upper Class HibernateQueryTool which i extends customerDao. BUT my hibernateTemplate is NULL on HibernateQueryTool -class, if i don't do upper class then my code works fine. I just don't get what im doing wrong here.

    Hopefully i you understand what i try to say

  • #2
    Please use [ code][/code ] tags when posting...

    Next I don't have a clue what your problem is...

    Comment


    • #3
      I hope it could help

      Code:
      <bean id="rootDao" class="RootDaoImpl" abstract="true">
      	<property name="hibernateTemplate">
      		<ref bean="hibernateTemplate"/>
      	</property> 
      </bean>
      
      
      <bean id="customerDao" class="CustomerDaoHibernateImpl" parent="rootDao">
      </bean>
      
      <bean id="hibernateQueryTool" class="HibernateQueryTool" parent="rootDao">
      </bean>

      Comment


      • #4
        I want to do upper Class HibernateQueryTool which i extends customerDao.
        Do you mean to say your class looks like "HibernateQueryTool extends CustomerDao"? That doesn't sound right.

        Perhaps if you posted some java code it would become clearer.

        Comment


        • #5
          Originally posted by cwilkes View Post
          Do you mean to say your class looks like "HibernateQueryTool extends CustomerDao"? That doesn't sound right.

          Perhaps if you posted some java code it would become clearer.
          Yes that is excatly what i want to do. Why? because i have couple methods on hibernateQueryTool class which i want to use other DAO classes (customerDao, userDao).

          like this:
          Code:
          public class HibernateQueryTool extends HibernateDaoSupport
          
          public class CustomerDaoHibernateImpl extends HibernateQueryTool implements CustomerDao

          Comment


          • #6
            Originally posted by kokkonen View Post

            like this:
            Code:
            public class HibernateQueryTool extends HibernateDaoSupport
            
            public class CustomerDaoHibernateImpl extends HibernateQueryTool implements CustomerDao
            Why don't you try this?

            Code:
            <bean id="rootDao" class="RootDaoImpl" abstract="true">
            	<property name="hibernateTemplate">
            		<ref bean="hibernateTemplate"/>
            	</property> 
            </bean>
            
            <bean id="hibernateQueryTool" class="HibernateQueryTool" parent="rootDao">
            </bean>
            
            <bean id="customerDao" class="CustomerDaoHibernateImpl" parent="hibernateQueryTool">
            </bean>

            Comment


            • #7
              sekobo thanks on advise, i try it but it didn't work maybe i do something wrong. If my application context looks like your wrote. how my HibernateQueryTools -class should looks like?

              public class HibernateQueryTool extends HibernateDaoSupport

              is that enough? My problem is still same that if i use this.getHibernateTemplate.delete(someObject); it'll throw exeption that session is closed. If i try to do this Session sessio=this.getHibernateTemplate.getSessionFactory ().openSession(); it'll return NULL

              Comment


              • #8
                Originally posted by kokkonen View Post
                sekobo thanks on advise, i try it but it didn't work maybe i do something wrong. If my application context looks like your wrote. how my HibernateQueryTools -class should looks like?

                public class HibernateQueryTool extends HibernateDaoSupport

                is that enough? My problem is still same that if i use this.getHibernateTemplate.delete(someObject); it'll throw exeption that session is closed. If i try to do this Session sessio=this.getHibernateTemplate.getSessionFactory ().openSession(); it'll return NULL
                First of all I think you have to create a rootDAO class

                Code:
                class RootDaoImpl extends HibernateDAOSupport{
                
                
                }
                
                class CustomerDaoHibernateImpl extends RootDaoImpl implements CustomerDao {
                
                }
                
                class HibernateQueryTool extends CustomerDaoHibernateImpl {
                
                }
                and then in your app context file you have to define your components

                Code:
                <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
                	<property name="sessionFactory">
                		<ref bean="sessionFactory" />
                	</property>
                </bean>
                
                <bean id="rootDao" class="RootDaoImpl" >
                	<property name="hibernateTemplate">
                		<ref bean="hibernateTemplate"/>
                	</property>
                </bean>
                
                <bean id="customerDao" class="CustomerDaoHibernateImpl" parent="rootDao">
                </bean>
                
                <bean id="hibernateQueryTool" class="HibernateQueryTool" parent="customerDao">
                </bean>
                Be sure that your session factory is well defined.
                Hope it will help.

                Comment


                • #9
                  First of all I think you have to create a rootDAO class
                  No you don't have to. What there has to be done however is that you specify a class on the rootDao bean definition. The class on the bean definition HAS to be a class that is a common superclass for all of your beans. If it doesn't fit the properties won't be set. So probably This class should be HibernateDaoSupport.

                  Code:
                  <bean id="rootDao" class="HibernateDaoSupport" abstract="true">
                  	<property name="hibernateTemplate">
                  		<ref bean="hibernateTemplate"/>
                  	</property> 
                  </bean>

                  Comment


                  • #10
                    Originally posted by mdeinum View Post
                    The class on the bean definition HAS to be a class that is a common superclass for all of your beans. If it doesn't fit the properties won't be set. So probably This class should be HibernateDaoSupport.
                    The rootDao class could be HibernateDaoSupport or a class that extends it, so if we have
                    Code:
                    class RootDaoImpl extends HibernateDaoSupport{
                    }
                    I think it is correct.

                    Comment


                    • #11
                      Well you could BUT that would also mean that ALL of your other daos would have to extend RootDaoImpl. If you want to work with the parent tag...

                      Comment

                      Working...
                      X