Results 1 to 2 of 2

Thread: How does the LocalSessionFactoryBean convert to SessionFacto

  1. #1
    Join Date
    Aug 2004
    Posts
    107

    Default How does the LocalSessionFactoryBean convert to SessionFacto

    My appContext has the following:

    <bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSess ionFactoryBean">
    <property name="dataSource"><ref bean="dataSource"/></property>
    <property name="mappingResources">
    <list>
    <value>org/appfuse/model/User.hbm.xml</value>
    </list>
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">net.sf.hibernate.dialect.P ostgreSQLDialect</prop>
    </props>
    </property>
    </bean>

    <bean id="userDAO" class="org.appfuse.persistence.hibernate.UserDAOHi bernate">
    <property name="sessionFactory"><ref local="sessionFactory"/></property>
    </bean>


    If I look at the setSessionFactory in HibernateDAOSupport the type of the argument is net.sf.hibernate.SessionFactory. However, my sessionFactory in the configuration file is of type org.springframework.orm.hibernate.LocalSessionFact oryBean. LocalSessionFactoryBean is not a descendant of SessionFactory. How does spring convert this?

    Dino

  2. #2
    Join Date
    Aug 2004
    Location
    Montréal, Canada
    Posts
    845

    Default

    First of all org.springframework.orm.hibernate.LocalSessionFact oryBean is a factory, it implements interface FactoryBean.
    When you ask Spring for a bean from your applicationContext (or references this bean in an other), Spring first checks the nature of your bean, if it implements interface FactoryBean, it will be treated as a factory, thus, Spring calls bean method getObject() and returns the object returned by that method.
    If you look at org.springframework.orm.hibernate.LocalSessionFact oryBean source you will find:
    Code:
    public class LocalSessionFactoryBean implements FactoryBean, InitializingBean, DisposableBean &#123;
      ...
      private SessionFactory sessionFactory;
      ...
    
      /**
       * Return the singleton SessionFactory.
       */
      public Object getObject&#40;&#41; &#123;
        return this.sessionFactory;
      &#125;
    &#125;
    Omar Irbouh

    Spring Modules Team
    http://irbouh.blogspot.com/

Similar Threads

  1. Replies: 7
    Last Post: Dec 20th, 2007, 06:00 AM
  2. Replies: 10
    Last Post: Apr 25th, 2005, 08:03 AM
  3. Replies: 2
    Last Post: Mar 11th, 2005, 05:17 AM
  4. Convert legacy code to Spring
    By rwspeh in forum Data
    Replies: 3
    Last Post: Feb 23rd, 2005, 09:59 PM
  5. Failed to convert property value
    By humberto in forum Container
    Replies: 1
    Last Post: Dec 14th, 2004, 09:32 PM

Posting Permissions

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