facebook

[Closed] Spring can not find Hibernate Config file

  1. MyEclipse Archived
  2.  > 
  3. Database Tools (DB Explorer, Hibernate, etc.)
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #259636 Reply

    Art Smith
    Member

    Hi,

    I created a web project and added hibernate and spring support using the wizards. In my applicationContext.xml file the location of my himernate config file is specified as:

    <bean id=”springSessionFactory”
    class=”org.springframework.orm.hibernate3.LocalSessionFactoryBean”>
    <property name=”configLocation”>
    <value>file:src/hibernate.cfg.xml</value>
    </property>
    </bean>

    My Hibernate config file contains:

    <?xml version=’1.0′ encoding=’UTF-8′?>
    <!DOCTYPE hibernate-configuration PUBLIC
    “-//Hibernate/Hibernate Configuration DTD 3.0//EN”
    http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd”&gt;

    <!– Generated by MyEclipse Hibernate Tools. –>
    <hibernate-configuration>

    <session-factory>
    <property name=”connection.username”>tomcat_sso</property>
    <property name=”connection.url”>
    jdbc:mysql://dev.ebcsnetwork.com:3306/tomcat_sso
    </property>
    <property name=”dialect”>
    org.hibernate.dialect.MySQLDialect
    </property>
    <property name=”myeclipse.connection.profile”>
    tomcat_sso
    </property>
    <property name=”connection.password”>admin</property>
    <property name=”connection.driver_class”>
    com.mysql.jdbc.Driver
    </property>
    <mapping
    resource=”com/ebcs/sso/service/hibernate/objects/AccountStatus.hbm.xml” />
    <mapping
    resource=”com/ebcs/sso/service/hibernate/objects/UserRoles.hbm.xml” />
    <mapping
    resource=”com/ebcs/sso/service/hibernate/objects/Role.hbm.xml” />
    <mapping
    resource=”com/ebcs/sso/service/hibernate/objects/Users.hbm.xml” />

    </session-factory>

    </hibernate-configuration>

    However, when I run on my local tomcat server I get:

    10:34:09,484 10/01 INFO cfg.Environment main Hibernate 3.1.3
    10:34:09,500 10/01 INFO cfg.Environment main hibernate.properties not found
    10:34:09,500 10/01 INFO cfg.Environment main using CGLIB reflection optimizer
    10:34:09,515 10/01 INFO cfg.Environment main using JDK 1.4 java.sql.Timestamp handling
    10:34:09,812 10/01 INFO cfg.Configuration main configuring from url: file:src/hibernate.cfg.xml
    10:34:09,828 10/01 INFO support.AbstractBeanFactory main Destroying singletons in factory {org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [appContext,AccountStatusDAO,UserRolesDAO,RoleDAO,UsersDAO]; root of BeanFactory hierarchy}
    10:34:09,828 10/01 ERROR factories.SpringApplicaitonContext main Problems were encountered while loading contexts!
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘appContext’ defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is org.hibernate.HibernateException: could not configure from URL: file:src/hibernate.cfg.xml
    org.hibernate.HibernateException: could not configure from URL: file:src/hibernate.cfg.xml
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1328)
    at org.springframework.orm.hibernate3.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:651)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1091)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:396)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:233)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:145)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:277)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:313)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:87)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:72)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:63)
    at com.ebcs.sso.common.factories.SpringApplicaitonContext.createFactory(SpringApplicaitonContext.java:31)
    at com.ebcs.sso.common.factories.SpringApplicaitonContext.init(SpringApplicaitonContext.java:17)
    at com.ebcs.sso.web.servlets.AppInit.initializeApplicationContext(AppInit.java:57)
    at com.ebcs.sso.web.servlets.AppInit.init(AppInit.java:65)
    at javax.servlet.GenericServlet.init(GenericServlet.java:211)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1105)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:932)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3917)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4201)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:759)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:739)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:524)
    at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:904)
    at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:867)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:474)
    at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1122)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:310)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1021)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:718)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1013)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:442)
    at org.apache.catalina.core.StandardService.start(StandardService.java:450)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:709)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:551)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:294)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:432)
    Caused by: java.io.FileNotFoundException: src\hibernate.cfg.xml (The system cannot find the path specified)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(FileInputStream.java:106)
    at java.io.FileInputStream.<init>(FileInputStream.java:66)
    at sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:70)
    at sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:161)
    at java.net.URL.openStream(URL.java:1007)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1325)
    … 41 more

    Can someone tell me how to tell spring how to find the hibernate config file. I assume that wizards would be build the correct code given the end user choices – I chose the default location.

    #259637 Reply

    Haris Peco
    Member

    ajs5mz2 ,

    Please, change configLocation to

    <property name=”configLocation”>
    <value>classpath:hibernate.cfg.xml</value>
    </property>

    Your hibernate.cfg.xml have to be in some source folder (now it is in src and it is okay)

    Best
    Peco

    #259638 Reply

    Art Smith
    Member

    Great… I got pass that problem.

    However, now I’m getting:
    java.lang.NoClassDefFoundError: org/hibernate/cfg/HbmBinder$SecondPass

    What class is it looking for? Again I assume that the wizards would add the requisite code so that I would not have to stumble thru this.

    #259639 Reply

    Haris Peco
    Member

    Class HbmBinder$SecondPass exists in hibernate 3.0 and doesn’t exist in hibernate 3.1

    You have some version mismatch.
    Please, can you describe your steps for making your application and send complete ‘NoClassDefFoundError:’ log

    Best
    Peco

    #259679 Reply

    Art Smith
    Member

    Peco,

    Yep.. that was the problem. When I created the project and added support I used the defaults. When adding Hibernate support myEclipse defaults to Hiberate 3.1. The Spring Support must only go up to version 3.0 of Hiberate, hence the problem.

    Thanks for your help.

    #259680 Reply

    Art Smith
    Member

    One more thing:

    if

    <property name=”configLocation”>
    <value>classpath:hibernate.cfg.xml</value>
    </property>

    is the correct way to specify the location on the hibernate conf file why does myEclipse use file:src ?

Viewing 6 posts - 1 through 6 (of 6 total)
Reply To: [Closed] Spring can not find Hibernate Config file

You must be logged in to post in the forum log in