Announcement Announcement Module
No announcement yet.
LocalSessionFactoryBean used in dynamic factory Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • LocalSessionFactoryBean used in dynamic factory

    I'm running Spring 3.0. I have an application that needs to connect to 130 data sources. It will read data from any n number of those data sources.

    Rather than having to support a static Spring configuration for each of these data sources; I have chosen to implement a factory that will create a persistence manager object for each data source. I simply converted the static implementation into a dynamic implementation.

    The LocalSessionFactoryBean does not appear to work outside of the Spring application context container. Here is the code:

                SpringHibernateLocalSessionFactoryPropertyHolder curPropertyHolder = entry.getValue();
          org.springframework.orm.hibernate3.LocalSessionFactoryBean newFactory = new org.springframework.orm.hibernate3.LocalSessionFactoryBean();
                newFactory.setMappingResources( curPropertyHolder.getMappingResources() );
                newFactory.setHibernateProperties( curPropertyHolder.getHibernateProperties() );
                newFactory.setDataSource( dataSource );
                SessionFactory sessionFactory = newFactory.getObject();
                org.springframework.orm.hibernate3.HibernateTransactionManager transactionManager = new org.springframework.orm.hibernate3.HibernateTransactionManager();
                transactionManager.setSessionFactory( sessionFactory );
    The problem is that newFactory.getObject() returns null. There are no exceptions thrown.

    Is LocalSessionFactoryBean designed to work in this manner or must it be instantiated from the container? I'm thinking that I need 1 instance per persistence manager, to remain consistent with the static implementation. That is why I am not injecting the instance.

    If I'm on the wrong track; what is the recommended solution?

    Thanks in advance for your assistance...

  • #2
    Some things I forgot to mention that adds complication to our design is that n number of data sources are selected for each user request and a query for each of the n data sources is performed concurrently. It is expected that an average load will hit at least 90% of the data sources.

    We also support the idea of a map of SessionFactory objects, where each item in the map supports a different set of mapping resources or schemas. The appropriate session factory is selected from a key in the request message.

    The design challenge I'm facing is how to best minimize the number of SessionFactory instances in memory.

    We deal with 130 data sources and 2 different schemas. The number of different schemas will increase over time into possible double digits.

    From what I'm reading of other experiences, even 50 SessionFactory objects would be too much to have in memory.

    We also have concerns over load/throughput but are not at a point where we can do load testing...

    Any suggestions/recommendations would be greatly appreciated...


    • #3
      I found the source code for LocalSessionFactoryBean and realized that afterPropertiesSet must be called... Still some interesting design challenges to tackle...