- This topic has 11 replies, 2 voices, and was last updated 18 years, 2 months ago by
Riyad Kalla.
-
AuthorPosts
-
SydneyOsMemberI 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
May 1, 2007 at 1:00 pm #269604
SydneyOsMemberI 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.
May 1, 2007 at 1:58 pm #269607
Riyad KallaMemberIs 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?
May 1, 2007 at 2:28 pm #269609
Riyad KallaMemberActually 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.
May 1, 2007 at 8:49 pm #269618
SydneyOsMemberThanks,
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.
May 1, 2007 at 9:30 pm #269622
Riyad KallaMemberAhh I mean, replace file:/hibernate.cfg.xml with what I pasted above.
May 1, 2007 at 10:01 pm #269626
SydneyOsMemberSorry 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
May 1, 2007 at 11:42 pm #269629
Riyad KallaMembernested 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?
May 2, 2007 at 9:27 am #269639
SydneyOsMemberI 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.
May 2, 2007 at 9:33 am #269641
Riyad KallaMemberSomething 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.htmlIt looks like they removed the class from the Hibernate 3 JAR in a maintenence release… that’s not good.
May 2, 2007 at 11:38 am #269648
SydneyOsMemberSo, what’s the solution? Roll back to the old version of the hibernate3.jar for Hibernate?
May 2, 2007 at 11:45 am #269649
Riyad KallaMemberIt 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.
-
AuthorPosts