Announcement Announcement Module
Collapse
No announcement yet.
Problem with dynamically loading hibernate mappings files Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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

    Comment

    Working...
    X