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}
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With