我试图让Spring和Hibernate在没有persistence.xml的情况下工作。我在我的context.xml文件上设置了我的实体包扫描程序,如下所示:
<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>
我错过了什么?
我一直收到错误:
No persistence units parsed from {classpath*:META-INF/persistence.xml}
答案 0 :(得分:4)
理想情况下,packagesToScan应该可以工作。
前 -
<property name="packagesToScan" value="tutorials.core.models.entities"></property>
如果它没有,那么你可以尝试这样的事情。 (根据文档,这是默认路径)
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml"></property>
...
</bean>
之后你应该在META-INF中添加persistence.xml(在src / main / resources下)
前 -
<?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>
由于