Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: No persistence units parsed from {classpath*:META-INF/persistence.xml}

I am trying to get Spring and Hibernate working without a persistence.xml. I am setting up my entities package scanner on my context.xml file, like this:

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration"/>
    <property name="hibernateProperties" ref="hibernatePropertiesConfigurer"/>
    <property name="packagesToScan" value="com.therubythree.simpleapi.entities"/>
</bean>

What am I missing?

I keep getting the error:

No persistence units parsed from {classpath*:META-INF/persistence.xml}
like image 737
marcelorocks Avatar asked Mar 14 '14 01:03

marcelorocks


1 Answers

Ideally, packagesToScan should work.

Ex -

<property name="packagesToScan" value="tutorials.core.models.entities"></property>

If it doesn't then you can try something like this. (according docs, this is the default path)

<bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml"></property>
    ...
</bean>

After that you should add the persistence.xml in the META-INF( under src/main/resources)

Ex -

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
version="1.0">
<persistence-unit name="studentPersistenceUnit" transaction-type="RESOURCE_LOCAL" >
<class>tutorials.models.entities.Student</class>
</persistence-unit>
</persistence>
like image 66
Manas Mukherjee Avatar answered Nov 16 '22 15:11

Manas Mukherjee