PDA

View Full Version : Spring - JPA not working



purnendu9
Mar 5th, 2008, 01:20 PM
Hi My Spring Hibernate JPA configuration is not working. The code is as below. Can you please help



<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
file:///C:/Development/Library/spring-framework-2.5-with-dependencies/spring-framework-2.5/dist/resources/spring-beans-2.5.xsd
http://www.springframework.org/schema/jee
file:///C:/Development/Library/spring-framework-2.5-with-dependencies/spring-framework-2.5/dist/resources/spring-jee-2.5.xsd
http://www.springframework.org/schema/tx
file:///C:/Development/Library/spring-framework-2.5-with-dependencies/spring-framework-2.5/dist/resources/spring-tx-2.5.xsd
">

<bean id='Test' class='persistence.Test'>
</bean>

<bean id='TestService' class='service.TestService'>
<property name="test" ref="Test"/>
</bean>

<jee:jndi-lookup id="dataSource" jndi-name="jdbc/contracting" lookup-on-startup="true" />

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityMa nagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="persistenceUnitName" value="ContractingPU"/>
<property name="jpaVendorAdapter">
<bean
class="org.springframework.orm.jpa.vendor.HibernateJpaVen dorAdapter">
<property name="database" value="MYSQL" />
<property name="showSql" value="true" />
<property name="databasePlatform" value="class org.hibernate.dialect.MySQL5Dialect"/>
</bean>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
<property name="dataSource" ref="dataSource"/>
</bean>
</beans>

the stack trace is as below



Caused by: java.lang.NoClassDefFoundError: org/hibernate/MappingException
at org.hibernate.ejb.HibernatePersistence.createConta inerEntityManagerFactory(HibernatePersistence.java :125)
at org.springframework.orm.jpa.LocalContainerEntityMa nagerFactoryBean.createNativeEntityManagerFactory( LocalContainerEntityManagerFactoryBean.java:221)
at org.springframework.orm.jpa.AbstractEntityManagerF actoryBean.afterPropertiesSet(AbstractEntityManage rFactoryBean.java:251)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.invokeInitMethods(Abstr actAutowireCapableBeanFactory.java:1390)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1359)
... 90 more
PWC1306: Startup of context /Contracting failed due to previous errors
PWC1412: WebModule[/Contracting] ServletContext.log():Closing Spring root WebApplicationContext

fenrir
Mar 5th, 2008, 11:56 PM
I think you forgot to include the hibernate.jar in the lib directory.

purnendu9
Mar 6th, 2008, 01:08 AM
I was doing permutation and combination. There were so many class not found errors. With hibernate3.jar included the error coming is


org.hibernate.HibernateException: Dialect class not found: class org.hibernate.dialect.MySQL5InnoDBDialect



<property name="databasePlatform" value="class org.hibernate.dialect.MySQL5InnoDBDialect"/>

fenrir
Mar 6th, 2008, 02:41 AM
try this link:
http://forum.springframework.org/archive/index.php/t-33414.html (http://forum.springframework.org/showthread.php?t=33414)

outersky
Mar 6th, 2008, 04:00 AM
since you suffer from library problems, maven will serve you very well.

purnendu9
Mar 6th, 2008, 03:03 PM
Yes i will Try Maven but i did not think it would be such a mess trying tie all these 3 together. I am seeing the dialect class being present in Hibernate3.jar and not being picked up

Strange and frustrating :)