Results 1 to 7 of 7

Thread: application context

  1. #1

    Default application context

    I have a GenericHibernateDAOSupport class which has some reusable code which every xxxDAO can use.
    Now, in my applicationcontext.xml file I want to define the sessionfactory for the GenericHibernateDAOSupport & not for every xxxDAO. How do I accomplish this? Any help is appreciated.

    I have a defn,
    <bean id="myxxxDAO" class="com.xxx.hibernate.xxxDAOHibernateImpl">
    <property name="sessionFactory"><ref local="mySessionFactory"/></property>
    </bean>
    <bean id="myGenericDAO" class="com.xxx.dao.GenericHibernateDAOSupport">
    <property name="sessionFactory"><ref local="mySessionFactory"/></property>
    </bean>

  2. #2
    Join Date
    Aug 2004
    Location
    Toronto, Canada
    Posts
    736

    Default

    One option is to make your DAOs inherit from the generic helper class. This is what Spring's HibernateDAOSupport class is for.

    Then, you would normally have to set the session factory for each dao instance, but if you use child bean definitions, you can get away from this:

    http://www.springframework.org/docs/...an-definitions

    Just make an abstract parent def which sets the sessionFactory, and the actual concrete DAOs would set that as the parent.

  3. #3

    Default

    Hi,
    Thanks a lot for the input.

    I tried using the child bean definitions as below but doesnt work:
    gives an exception :
    Caused by: java.lang.IllegalArgumentException: sessionFactory or hibernateTemplate is required

    <!-- DAO object: Hibernate implementation -->
    <bean id="myGenericDAO" class="com.xxx.dao.GenericHibernateDAOSupport">
    <property name="sessionFactory"><ref local="mySessionFactory"/></property></bean>
    <bean id="myDatadeliverabletrackingDAO" class="com.xxx.dao.hibernate.Datadeliverabletracki ngDAOHibernateImpl"
    parent="myGenericDAO" >
    </bean>

  4. #4
    Join Date
    Aug 2004
    Location
    Toronto, Canada
    Posts
    736

    Default

    The parent bean def shouldn't have a class first of all, it's just an abstract definition. And it should be set to lazy-init so Sprig doesn't try to create it.

    Where are yuo getting the error though?

    Regards,
    Colin Sampaleanu
    SpringSource - http://www.springsource.com

  5. #5

    Default application context

    I am using junit to test my code. In my test class I get an handle of the bean "myDatadeliverabletrackingDAO" and then access the methods defined. I tried changing my code as mentioned, still doesnt work!!!

    <!-- DAO object: Hibernate implementation -->
    <bean id="myGenericDAO" lazy-init="true">
    <property name="sessionFactory"><ref local="mySessionFactory"/></property></bean>
    <bean id="myDatadeliverabletrackingDAO" class="com.xxx.dao.hibernate.Datadeliverabletracki ngDAOHibernateImpl"
    parent="myGenericDAO" >
    </bean>

  6. #6
    Join Date
    Aug 2004
    Location
    Toronto, Canada
    Posts
    736

    Default

    Child bean definitions got a lot more powerful as of 1.1RC1. Are you using 1.1RC1 or 1.1RC2?

    Regards,
    Colin Sampaleanu
    SpringSource - http://www.springsource.com

  7. #7

    Default application context

    That worked! I got spring 1.1RC2 and the child bean definitions worked.

    Thanks a bunch.

Similar Threads

  1. Loosing my SecureContext
    By sklakken in forum Security
    Replies: 3
    Last Post: Jul 21st, 2005, 01:44 PM
  2. Stack Overflow
    By rayho222 in forum Container
    Replies: 6
    Last Post: May 17th, 2005, 03:42 AM
  3. Replies: 6
    Last Post: May 8th, 2005, 11:09 AM
  4. Questioning the core component
    By Martin Kersten in forum Swing
    Replies: 6
    Last Post: Feb 21st, 2005, 03:45 AM
  5. Hierarchical application context in J2EE app
    By cmgharris in forum Container
    Replies: 2
    Last Post: Sep 13th, 2004, 04:13 AM

Posting Permissions

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