【问题标题】:Error: No persistence units parsed from {classpath*:META-INF/persistence.xml}错误:没有从 {classpath*:META-INF/persistence.xml} 解析的持久性单元
【发布时间】:2014-03-14 01:30:26
【问题描述】:

我正在尝试让 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}

【问题讨论】:

    标签: xml spring hibernate


    【解决方案1】:

    理想情况下,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(src/main/resources 下)中添加 persistence.xml

    前-

    <?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>
    

    【讨论】:

    猜你喜欢
    • 2012-07-24
    • 1970-01-01
    • 1970-01-01
    • 2014-10-02
    • 1970-01-01
    • 1970-01-01
    • 2013-08-18
    • 2011-05-25
    • 2023-03-18
    相关资源
    最近更新 更多