-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 posts ] 
Author Message
 Post subject: Hibernate and Spring (problem with springapp-servlet.xml)
PostPosted: Tue Jun 22, 2004 8:59 am 
Beginner
Beginner

Joined: Tue Jun 22, 2004 7:50 am
Posts: 25
Hi

Hope someone can help.

Got a Spring application up and running (in Tomcat 5) following a tutorial. Decided to convert it to using Hibernate and bang! hit a brick wall.

I get this Exception when I open the page that does a DB read:

Code:
org.springframework.beans.factory.BeanDefinitionStoreException: Line 81 in XML document from resource [/WEB-INF/springapp-servlet.xml] of ServletContext is invalid; nested exception is org.xml.sax.SAXParseException: The content of element type "property" must match "(description?,(bean|ref|idref|list|set|map|props|value|null))"


Funny thing is that all my <property> elements do contain the correct content. The other funny thing is that the exception sometimes changes to complain about a class not being found (either javax/transaction/transaction or javax/transaction/SystemException or someting similar).

Anyone have any idea please ?

Edward

PS Here's my springapp-servlet.xml that it's complaining about

[code]
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">

<!--
- Application context definition for "springapp" DispatcherServlet.
-->

<beans>

<!-- Controller for the initial "Hello" page -->
<bean id="springappController" class="web.SpringappController">
<property name="productManager">
<ref bean="prodMan"/>
</property>
</bean>

<!-- Validator and Form Controller for the "Price Increase" page -->
<bean id="priceIncreaseValidator" class="bus.PriceIncreaseValidator"/>
<bean id="priceIncreaseForm" class="web.PriceIncreaseFormController">
<property name="sessionForm"><value>true</value></property>
<property name="commandName"><value>priceIncrease</value></property>
<property name="commandClass"><value>bus.PriceIncrease</value></property>
<property name="validator"><ref bean="priceIncreaseValidator"/></property>
<property name="formView"><value>priceincrease</value></property>
<property name="successView"><value>hello.htm</value></property>
<property name="productManager">
<ref bean="prodMan"/>
</property>
</bean>

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName"><value>org.hsqldb.jdbcDriver</value></property>
<property name="url">
<value>jdbc:hsqldb:/Users/edward/Development/Java/springapp/db/test</value>
</property>
<property name="username"><value>sa</value></property>
<property name="password"><value/></property>
</bean>

<!-- -->
<!-- Hibernate SessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean">
<property name="dataSource"><ref local="dataSource"/></property>

<!-- Must references all OR mapping files. -->
<property name="mappingResources">
<list>
<value>db/Product.hbm.xml</value>
</list>
</property>

<!-- Set the type of database; changing this one property will port this to Oracle, MS SQL etc. -->
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">net.sf.hibernate.dialect.HSQLDialect</prop>
</props>
</property>
</bean>

<bean id="prodManDao" class="db.ProductManagerDaoHibernate">
<property name="sessionFactory"><ref local="sessionFactory"/></property>
</bean>

<bean id="prodMan" class="bus.ProductManager">
<property name="productManagerDao">
<ref bean="prodManDao"/>
</property>
</bean>

<!-- -->
<bean id="MyTransactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"/>

<bean id="MyTransactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager"><ref bean="MyTransactionManager"/></property>
<property name="transactionAttributeSource">
<value>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 22, 2004 10:06 am 
Senior
Senior

Joined: Wed Aug 27, 2003 6:04 am
Posts: 161
Location: Linz, Austria
I don't know why the exception varies, but you definitely need jta.jar (with javax.transaction.* classes) on the classpath. That's a Hibernate requirement, not a Spring requirement.

Juergen


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 22, 2004 10:16 am 
Beginner
Beginner

Joined: Tue Jun 22, 2004 7:50 am
Posts: 25
Thanks very much- I had missed that jar and have copied that over.

Still get the same exception though- which is bizarre because my editor confirms my -applet.xml file conforms to the DTD! I'll carry on fiddling.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 22, 2004 1:23 pm 
Beginner
Beginner

Joined: Tue Jun 22, 2004 7:50 am
Posts: 25
CountBrass wrote:
Thanks very much- I had missed that jar and have copied that over.

Still get the same exception though- which is bizarre because my editor confirms my -applet.xml file conforms to the DTD! I'll carry on fiddling.



Well some more fiddling and I'm now getting:

...defined in resource [/WEB-INF/springapp-servlet.xml] of ServletContext: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: null

NoClassDefFoundError null ??

Sounds like a silly mistake on my part but I just can't see any difference between my code and the examples from the documentation.

Help please?!?

Edward


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 23, 2004 10:19 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Do you have the hsqldb jar in the classpath? I have seen that error before when the classloader is unable to find a suitable jdbc driver on the classpath.

What is the stack trace of the java.lang.NoClassDefFoundError: null exception?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 23, 2004 10:29 am 
Beginner
Beginner

Joined: Tue Jun 22, 2004 7:50 am
Posts: 25
steve wrote:
Do you have the hsqldb jar in the classpath? I have seen that error before when the classloader is unable to find a suitable jdbc driver on the classpath.

What is the stack trace of the java.lang.NoClassDefFoundError: null exception?


Hi Steve, yes hsqldb.jar is in the classpath (WEB-INF/lib same as the other jars).

The stack trace is:

Code:
root cause <pre>org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springappController' defined in resource [/WEB-INF/springapp-servlet.xml] of ServletContext: Can't resolve reference to bean 'prodMan' while setting property 'productManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'prodMan' defined in resource [/WEB-INF/springapp-servlet.xml] of ServletContext: Can't resolve reference to bean 'prodManDao' while setting property 'productManagerDao'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'prodManDao' defined in resource [/WEB-INF/springapp-servlet.xml] of ServletContext: Can't resolve reference to bean 'sessionFactory' while setting property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in resource [/WEB-INF/springapp-servlet.xml] of ServletContext: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: null
   org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.resolveReference(AbstractAutowireCapableBeanFactory.java:723)
   org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.resolveValueIfNecessary(AbstractAutowireCapableBeanFactory.java:672)
   org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:614)
   org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:467)
   org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:232)
   org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:177)
   org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:159)
   org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:183)
   org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:268)
   org.springframework.web.context.support.XmlWebApplicationContext.refresh(XmlWebApplicationContext.java:131)
   org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:281)
   org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:229)
   org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:199)
   org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:102)
   javax.servlet.GenericServlet.init(GenericServlet.java:211)
   org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
   org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
   org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:793)
   org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:702)
   org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:571)
   org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:644)
   java.lang.Thread.run(Thread.java:552)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 23, 2004 10:34 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Well then my two suggestions would be 1) make sure you have all of Hibernate's dependencies avaliable on your classpath; 2) set both Spring and Hibernate logging to debug and see what is going on when the exception occurs.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 23, 2004 1:46 pm 
Beginner
Beginner

Joined: Tue Jun 22, 2004 7:50 am
Posts: 25
steve wrote:
Well then my two suggestions would be 1) make sure you have all of Hibernate's dependencies avaliable on your classpath; 2) set both Spring and Hibernate logging to debug and see what is going on when the exception occurs.


Ah ha!

Looks like it was a hibernate dependency problem. Getting a new exception now: but this one I understand (java.lang.IllegalStateException: No Hibernate Session bound to thread, and configuration does not allow creation of new one here). Thanks very much for your help!

Now I just have to work out which of the 31 extra jar files I copied from Hibernates lib dir I can safely delete :-)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 23, 2004 10:10 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
In the distro, look at the lib/README.txt file. It'll tell you what type of dependency Hibernate has on particular jars. You'll only need the jars marked as "runtime, required" (and possibly "runtime, optional" if using optional features requiring that jar).


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 23, 2004 11:27 pm 
Beginner
Beginner

Joined: Tue Jun 22, 2004 7:50 am
Posts: 25
Ah! Thanks very much for your help!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.