【发布时间】:2014-01-16 02:39:27
【问题描述】:
已经把persistence.xml放在eclipse项目的classpath中 因为之前的错误是找不到文件。 现在给出这个错误:
原因:javax.persistence.PersistenceException:无效 持久性.xml。解析 XML 时出错 [行:-1,列:-1]: cvc-elt.1:找不到元素“持久性”的声明
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.1"
xsi:schemalocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="default" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
<property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/Automoveis" />
<property name="javax.persistence.jdbc.user" value="postgres" />
<property name="javax.persistence.jdbc.password" value="1234" />
<property name="javax.persistence.jdbc.driver" value="org.postgresql.jdbc.Driver" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
<property name="hibernate.hbm2ddl.auto" value="create" />
</properties>
</persistence-unit>
</persistence>
【问题讨论】:
-
请正确格式化 XML。摆脱所有那些
>。 -
几周前我遇到了同样的问题。您是手动创建 entityManagerFactory 吗?看起来您正在将“persistence.xml”传递给无法打开/找到此文件的构造函数。对我来说,当实体管理器由容器创建时一切正常。
标签: java hibernate jpa persistence