Estoy desarrollando una aplicación web con spring y jpa mediante el IDE netbeans.
Estoy intentando configurar jpa con el fichero persistence.xml y el applicationContext.xml.
Ahora mismo tengo creado el fichero persistence.xml tal como se muestra a continuación:
Código:
y el fichero ApplicationContext.xml<?xml version="1.0" encoding="UTF-8"?> <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"> <persistence-unit name="RanquingsPU" transaction-type="RESOURCE_LOCAL"> <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> <class>com.Ranquings.Domain.Tipusranquing</class> <class>com.Ranquings.Domain.Tipususuari</class> <class>com.Ranquings.Domain.Ranquings</class> <class>com.Ranquings.Domain.Tipuscomentari</class> <class>com.Ranquings.Domain.Faq</class> <class>com.Ranquings.Domain.Comentaris</class> <class>com.Ranquings.Domain.Pais</class> <class>com.Ranquings.Domain.Sectors</class> <class>com.Ranquings.Domain.Usuaris</class> <class>com.Ranquings.Domain.Tipusdocument</class> <class>com.Ranquings.Domain.Documents</class> <class>com.Ranquings.Domain.Ciutat</class> <exclude-unlisted-classes>false</exclude-unlisted-classes> <properties> <property name="javax.persistence.jdbc.url" value="jdbc:derby://localhost:1527/Ranquings"/> <property name="javax.persistence.jdbc.password" value="josedd"/> <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/> <property name="javax.persistence.jdbc.user" value="jose"/> </properties> </persistence-unit> </persistence>
Código:
he añadido las librerias de persistence, hibernate(jpa) y eclipselink. La libreria de Spring viene por defecto<?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:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd" xmlns:context="http://www.springframework.org/schema/context"> <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="persistenceUnitName" value="RanquingsPU"/> <property name="jpaVendorAdapter"> <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> <property name="databasePlatform" value="oracle.toplink.essentials.platform.database.DerbyPlatform" /> <property name="showSql" value="true" /> <property name="database" value="DERBY" /> </bean> </property> </bean> <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> <property name="basenames" value="/WEB-INF/classes/messages" /> </bean> <bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver"> <property name="defaultLocale" value="es"/> </bean> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="org.apache.derby.jdbc.ClientDriver"/> <property name="url" value="jdbc:derby://localhost:1527/Ranquings"/> <property name="username" value="jose"/> <property name="password" value="josedd"/> </bean> <tx:annotation-driven transaction-manager="transactionManager" /> <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="entityManagerFactory" /> <property name="dataSource" ref="dataSource"/> </bean> <bean id="jpaTemplate" class="org.springframework.orm.jpa.JpaTemplate"> <property name="entityManagerFactory" ref="entityManagerFactory" /> </bean> </beans>
Y a la hora de compilarlo me da este error:
Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: JPA PersistenceProvider returned null EntityManagerFactory - check your JPA provider setup!
Segun he mirado por internet todos dicen que es porque no tiene la definición del persistence provider en el application context y yo si lo tengo...no se que puede ser..ahora mismo...No se si me falta alguna libreria o tengo que configurar alguna otra cosa...
Alguien me ayuda
Gracias