找不到元素“持久性”的声明 [英] Can not find the declaration of element 'persistence'
本文介绍了找不到元素“持久性”的声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
已将persistence.xml放入eclipse
中的项目的类路径中,因为在错误之前找不到该文件。
现在给出这个错误:
lockquote
引起:javax.persistence.PersistenceException:
persistence.xml无效。错误解析XML [line:-1,column:-1]:
cvc-elt.1:无法找到元素'persistence'的声明
< persistence xmlns =http://java.sun.com/xml/ns/persistence
xmlns:xsi =http: //www.w3.org/2001/XMLSchema-instanceversion =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 =defaulttransaction-type =RESOURCE_LOCAL>
< provider> org.hibernate.ejb.HibernatePersistence< / provider>
<属性>
< property name =hibernate.dialectvalue =org.hibernate.dialect.PostgreSQLDialect/>
< property name =javax.persistence.jdbc.urlvalue =jdbc:postgresql:// localhost:5432 / Automoveis/>
< property name =javax.persistence.jdbc.uservalue =postgres/>
< property name =javax.persistence.jdbc.passwordvalue =1234/>
< property name =javax.persistence.jdbc.drivervalue =org.postgresql.jdbc.Driver/>
< property name =hibernate.show_sqlvalue =true/>
< property name =hibernate.format_sqlvalue =true/>
< property name =hibernate.hbm2ddl.autovalue =create/>
< / properties>
< / persistence-unit>
< /余辉>
解决方案
解决!
我不知道到底发生了什么问题,但它运行良好:
< persistence version = 2.0
xmlns =http://java.sun.com/xml/ns/persistencexmlns:xsi =http://www.w3.org/2001/XMLSchema-instance
xsi:schemaLocation =http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd\">
< persistence-unit name =defaulttransaction-type =RESOURCE_LOCAL>
< provider> org.hibernate.ejb.HibernatePersistence< / provider>
<属性>
< property name =javax.persistence.jdbc.drivervalue =org.postgresql.Driver/>
< property name =javax.persistence.jdbc.urlvalue =jdbc:postgresql:// localhost:5432 / Automoveis/>
< property name =javax.persistence.jdbc.uservalue =postgres/>
< property name =javax.persistence.jdbc.passwordvalue =1234/>
< property name =hibernate.dialectvalue =org.hibernate.dialect.PostgreSQLDialect/>
< property name =hibernate.hbm2ddl.autovalue =update/>
< property name =hibernate.show_sqlvalue =true/>
< property name =hibernate.format_sqlvalue =true/>
< / properties>
< / persistence-unit>
Have put the persistence.xml in the classpath of the project in eclipse because before the error was that the file was not found. Now gives this error:
Caused by: javax.persistence.PersistenceException: Invalid persistence.xml. Error parsing XML [line : -1, column : -1] : cvc-elt.1: Can not find the declaration of element 'persistence'
<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>
解决方案
Solved!
I do not know exactly what was wrong, but it worked well:
<persistence version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="default" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" />
<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="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true"/>
</properties>
</persistence-unit>
这篇关于找不到元素“持久性”的声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文