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

I am trying to get Spring and Hibernate to work without persistence.xml. I configure my batch package of objects in my context.xml file, for example:

<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}
+4
source share
1 answer

Ideally, packageToScan should work.

Ex -

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

If this is not the case, you can try something like this. (according to the 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 persistence.xml to META-INF (in the src / main / resources section)

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>

thank

+4
source

Source: https://habr.com/ru/post/1531682/


All Articles