-
Error using JPA
When I run my application with this context:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="profissionalDao"
class="persistence.profissional.ProfissionalDao">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="true" />
<property name="generateDdl" value="true" />
<property name="databasePlatform"
value="org.hibernate.dialect.OracleDialect" />
</bean>
</property>
<property name="loadTimeWeaver">
<bean class="org.springframework.instrument.classloading.SimpleLoadTimeWeaver" />
</property>
</bean>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="oracle.jdbc.OracleDriver" />
<property name="url" value="jdbc:oracle:thin:@oracle8:1521:DB" />
<property name="username" value="user" />
<property name="password" value="pass" />
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="teste" class="Teste">
<property name="profissionalDao">
<ref bean="profissionalDao" />
</property>
</bean>
</beans>
and my persistence.xml in META-INF/
Code:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
<persistence-unit name="Teste">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
</persistence-unit>
</persistence>
but the following error shows:
Code:
aused by: java.lang.IllegalStateException: No persistence units parsed from {classpath*:META-INF/persistence.xml}
whats happens?
-
Have you tried removing the load-time weaver? I think you don't need to include it when using the Hibernate JPA provider.
Cheers,
Spiff
-
Yes, you don't need the loadtime weaver when you use Hibernate. Also you should specify transaction-type="RESOURCE_LOCAL" for the persistence-unit since the default is JTA transactions.
I don't think these issues cause your problem though. It must be that the persistence.xml is not in the right place - what is your runtime directory structure? It should be located in "classes/META-INF" where classes would be part of your class path.
-
Are you running Spring 2.0 or a RC? There has been a change to look for classpath*:META-INF/persistence.xml before RC4 I believe since in applications with multiple libraries (and thus multiple roots inside the classpath), the file could not be found.
-
Spring doesn't find your persistence.xml. For example in an Eclipse RCP application add a new folder META-INF UNDER your source folder (e.g. src->META-INF) and put your persistence.xml in there (now you've got TWO META-INF folders).
Cheers Tom
-
Yes The path of persistence.xml is different now. It will look under src/META-INF