Results 1 to 3 of 3

Thread: How to initialise Hibernate from existing hibernate.cfg.xml?

  1. #1

    Default How to initialise Hibernate from existing hibernate.cfg.xml?

    I had an existing project using Hibernate and now want to move to Spring.

    The demo on Spring reference sets all hibernate properties for LocalSessionFactoryBean. However, as I read the Spring Javadoc of LocalSessionFactoryBean class, you can actually specify an existing hibernate.cfg.xml file. (LocalSessionFactoryBean.setConfigLocation(Resourc e configLocation) ).

    My question is, how do I configure this in my applicationContext.xml file?
    I guess it should be something look like this, but not exactly sure:

    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean">
    <property name="configLocation">
    <value>/WEB-INF/hibernate.cfg.xml</value>
    </property>
    </bean>

    because the setConfigLocation takes a Resource parameter, but not a String, so I guess I must do something to get a Resource bean which is my hibernate.cfg.xml

  2. #2
    Join Date
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,104

    Default

    You can try:
    Code:
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
      <property name="configLocation">
        <value>classpath&#58;hibernate.cfg.xml</value>
      </property>
    </bean>

  3. #3

    Default Thanks, it works!!

    Thanks a lot!!

Similar Threads

  1. Replies: 5
    Last Post: Dec 27th, 2005, 07:00 AM
  2. Loosing my SecureContext
    By sklakken in forum Security
    Replies: 3
    Last Post: Jul 21st, 2005, 01:44 PM
  3. Replies: 3
    Last Post: Nov 19th, 2004, 07:16 PM
  4. Replies: 9
    Last Post: Sep 25th, 2004, 12:35 PM
  5. Replies: 7
    Last Post: Aug 21st, 2004, 03:42 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
  •