我正在使用eclipse中的spring jpa hibernate进行项目。我的persistence.xml文件有错误,但我不知道到底在哪里:
我的persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
<persistence-unit name="hibernatePersistenceUnit" transaction-type="RESOURCE_LOCAL">
<properties>
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="show_sql">true</property>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
</properties>
<mapping-file>META-INF/orm.xml</mapping-file>
</persistence-unit>
</persistence>
我收到的错误就像这样:
javax.persistence.PersistenceException: Invalid persistence.xml.
Error parsing XML (line-1 : column -1): cvc-complex-type.4: Attribute 'value' must appear on element 'property'.
Error parsing XML (line-1 : column -1): cvc-complex-type.2.1: Element 'property' must have no character or element information item [children], because the type's content type is empty.
Error parsing XML (line-1 : column -1): cvc-complex-type.2.4.d: Invalid content was found starting with element 'mapping-file'. No child element is expected at this point.
at org.hibernate.ejb.packaging.PersistenceXmlLoader.loadURL(PersistenceXmlLoader.java:145)
at org.hibernate.ejb.packaging.PersistenceXmlLoader.deploy(PersistenceXmlLoader.java:169)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:317)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:56)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:46)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:30)
at org.krams.repository.CustomerDAO.addCustomer(CustomerDAO.java:38)
at org.krams.repository.CustomerDAO$$FastClassByCGLIB$$60d23388.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191)
有没有人可以帮我解决这个问题。
答案 0 :(得分:0)
尝试将映射文件放在属性之前:
<?xml version="1.0" encoding="UTF-8"?>
<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="hibernatePersistenceUnit" transaction-type="RESOURCE_LOCAL">
<mapping-file>META-INF/orm.xml</mapping-file>
<properties>
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="show_sql" value="true"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
</properties>
</persistence-unit>
</persistence>