Announcement Announcement Module
Collapse
No announcement yet.
How to initialise Hibernate from existing hibernate.cfg.xml? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

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

    Comment


    • #3
      Thanks, it works!!

      Thanks a lot!!

      Comment

      Working...
      X