facebook

Spring-Hibernate: could not configure from URL:

  1. MyEclipse IDE
  2.  > 
  3. Java EE Development (EJB, JSP, Struts, XDoclet, etc.)
Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #269602 Reply

    SydneyOs
    Member

    I followed the tutorial on using Hibernate and Spring together (http://www.myeclipseide.com/images/tutorials/quickstarts/hibernate_and_spring/tutorial.html) and ended up with the following in my applicationContext.xml:

    <bean id=”hibernateSession”
    class=”org.springframework.orm.hibernate3.LocalSessionFactoryBean”>
    <property name=”configLocation”>
    <value>file:src/hibernate.cfg.xml</value>
    </property>
    </bean>
    <bean id=”InternetLoginDAO” class=”com.gensa.cc.InternetLoginDAO”>
    <property name=”sessionFactory”>
    <ref bean=”hibernateSession” />
    </property>
    </bean>
    <bean id=”persistInternetLogin”
    class=”com.gensa.cc.spring.PersistInternetLogin” abstract=”false”
    singleton=”true” lazy-init=”default” autowire=”default”
    dependency-check=”default”>
    <property name=”internetLoginDAO”>
    <ref bean=”InternetLoginDAO” />
    </property>
    </bean>

    and this in my hibernate.cfg.xml file:

    <hibernate-configuration>
    <session-factory>
    <property name=”connection.username”>username</property>
    <property name=”connection.url”>jdbc:oracle:thin:@localhost:1521:XE</property>
    <property name=”dialect”>org.hibernate.dialect.Oracle9Dialect</property>
    <property name=”myeclipse.connection.profile”>Canine Companions</property>
    <property name=”connection.password”>password</property>
    <property name=”connection.driver_class”>oracle.jdbc.driver.OracleDriver</property>
    <mapping resource=”com/gensa/cc/InternetLogin.hbm.xml” />
    </session-factory>
    </hibernate-configuration>

    The connection info works for the DB Browser.

    However, when I try to instantiate the persistInternetLogin bean thusly:

    BeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource(
    “applicationContext.xml”));

    PersistInternetLogin persistenceLayer = (PersistInternetLogin) beanFactory
    .getBean(“persistInternetLogin”);

    I get the following error:

    Error creating bean with name ‘persistInternetLogin’ defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean ‘InternetLoginDAO’ while setting bean property ‘internetLoginDAO’;

    nested exception is org.springframework.beans.factory.BeanCreationException:

    Error creating bean with name ‘InternetLoginDAO’ defined in class path resource [applicationContext.xml]:

    Cannot resolve reference to bean ‘hibernateSession’ while setting bean property ‘sessionFactory’;

    nested exception is org.springframework.beans.factory.BeanCreationException:

    Error creating bean with name ‘hibernateSession’ 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

    #269604 Reply

    SydneyOs
    Member

    I should add that I am using Spring 1.2.2 and Hibernate 3.1 and MyEclipse 5.1.1 GA and Eclipse 3.2.

    Really appreciate any help – I’m sure it’s something obvious to anyone but me.

    #269607 Reply

    Riyad Kalla
    Member

    Is your hibernate.cfg.xml file in the root of your /src folder?Are you running this as a web app or as a stand alone app?

    #269609 Reply

    Riyad Kalla
    Member

    Actually I just ran across a bug in our issue tracker pertaining to this. If your project had web capabilities on it, it would have entered the path as:

    classpath:/hibernate.cfg.xml

    which works in a web app. Try that.

    #269618 Reply

    SydneyOs
    Member

    Thanks,

    Yes, it’s a Web App.

    Do you mean file: /hibernate.cfg.xml? in the applicationContext.xml file? If so, that doesn’t work, either.

    I’m not sure I follow where the ‘classpath’ is coming from.

    The hibernate file is in the src root.

    #269622 Reply

    Riyad Kalla
    Member

    Ahh I mean, replace file:/hibernate.cfg.xml with what I pasted above.

    #269626 Reply

    SydneyOs
    Member

    Sorry to be dense, but you mean this:

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

    If so, here’s what I get (something new and different):

    Error creating bean with name ‘persistInternetLogin’ defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean ‘InternetLoginDAO’ while setting bean property ‘internetLoginDAO’; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘InternetLoginDAO’ defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean ‘hibernateSession’ while setting bean property ‘sessionFactory’; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘hibernateSession’ defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: org/hibernate/cfg/HbmBinder$SecondPass

    #269629 Reply

    Riyad Kalla
    Member

    nested exception is java.lang.NoClassDefFoundError: org/hibernate/cfg/HbmBinder$SecondPass

    Hmm, looks like the Hibernate libraries may not be getting deployed properly. Did you check your deployment dir to see if they are in there? And did you try and open hibernate.jar and dig down into org/hibernate/cfg/HbmBinder and see if it has an inner class SecondPass?

    #269639 Reply

    SydneyOs
    Member

    I did. The hibernate3.jar that MyEclipse adds when adding Spring (Spring 1.2 ORM/DAO/Hibernate3 Libraries) capabilities has it. The hibernate3.jar that MyEclipse adds when adding Hibernate (Hibernate 3.1 Core Libraries) capabilities does not have it. I did use MyEclipse to add Hibernate capabilities (3.1) first and then Spring (selecting Hibernate 3 as the option). So, I don’t know how MyEclipse decides which jar to use.

    #269641 Reply

    Riyad Kalla
    Member

    Something is going on then, because when I just double-checked this locally, the Spring and Hibernate libraries are the same, neither had the $SecondPass internal class oddly enough.

    As it turns out this is a known Hibernate + Spring issue:
    http://forum.springframework.org/archive/index.php/t-20553.html

    It looks like they removed the class from the Hibernate 3 JAR in a maintenence release… that’s not good.

    #269648 Reply

    SydneyOs
    Member

    So, what’s the solution? Roll back to the old version of the hibernate3.jar for Hibernate?

    #269649 Reply

    Riyad Kalla
    Member

    It seems to be, this is the first time I’m seeing this issue with hibernate/spring, I’m not sure how far back you need to go. The thread might shine some light on exactly which version.

Viewing 12 posts - 1 through 12 (of 12 total)
Reply To: Spring-Hibernate: could not configure from URL:

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