Results 1 to 2 of 2

Thread: Problem with dynamically loading hibernate mappings files

  1. #1
    Join Date
    Jan 2005
    Posts
    3

    Default Problem with dynamically loading hibernate mappings files

    hi.
    For the project I'm working on, I need to load a different mappings file for a class based on a parameter passed into the method.
    Using hibernate on its won, this is posssible by creating an instance of the Configuration class and calling its loadFile(String fileName) method. However no such way seems to exist when using Spring with hibernate.
    Here is my current code.

    init code
    ctx = new ClassPathXmlApplicationContext("applicationContext .xml");
    myDao = (MyDAO) ctx.getBean("MyDAO"); // loads dao bean

    This is my current applicationContext.xml
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
    "http://www.springframework.org/dtd/spring-beans.dtd">
    <beans>
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverM anagerDataSource">
    <property name="driverClassName"><value>oracle.jdbc.OracleDr iver</value></property>
    <property name="url"><value>jdbc:oracle:thin:@ktnammkt2.fmr. com:1521:ktnad1</value></property>
    <property name="username"><value>ktnasndcoe</value></property>
    <property name="password"><value>coektnasnd </value></property>
    </bean>

    <!-- Hibernate SessionFactory -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSess ionFactoryBean">
    <property name="dataSource"><ref local="dataSource"/></property>
    <property name="mappingResources">
    <list>
    <value>com/fid/itgc/dao/FPCMS.hbm.xml</value>
    </list>
    </property>
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">net.sf.hibernate.dialect.O racle9Dialect</prop>
    </props>
    </property>
    </bean>

    <!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->
    <bean id="transactionManager" class="org.springframework.orm.hibernate.Hibernate TransactionManager">
    <property name="sessionFactory"><ref local="sessionFactory"/></property>
    </bean>

    <bean id="SpringITGCDAO" class="com.fid.itgc.dao.SpringITGCDAO">
    <property name="sessionFactory"><ref local="sessionFactory"/></property>
    </bean>
    </beans>

    Would greatly appreciate any help.

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

    Default

    For the project I'm working on, I need to load a different mappings file for a class based on a parameter passed into the method.
    Are you creating a new SessionFactory on each method call? such approach is not scallable.
    Could you expand more on your need?
    HTH
    Omar Irbouh

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

Similar Threads

  1. Hibernate Long Session Per Flow?
    By akw in forum Web Flow
    Replies: 21
    Last Post: Dec 12th, 2005, 08:06 PM
  2. Cannot locate hibernate mappings files in jar
    By rnayani in forum Container
    Replies: 4
    Last Post: Jul 24th, 2005, 05:25 AM
  3. Replies: 1
    Last Post: Jul 5th, 2005, 03:48 AM
  4. Replies: 3
    Last Post: May 16th, 2005, 07:04 AM
  5. Replies: 3
    Last Post: Nov 19th, 2004, 07:16 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
  •