[英]SAXException=XML document structures must start and end within the same entity
[英]XML document structures must start and end within the same entity
使用 JAVA、JPA、MAVEN、MYSQL 技术制作从数据库插入和检索数据的小项目时出现错误。 下面是我的代码。
这是我的 persistence.xml 代码:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1"
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="JEETut3" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<class>com.newthinktank.JEETut3.Customer</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost/test4"/>
<property name="javax.persistence.jdbc.user" value="testuser"/>
<property name="javax.persistence.jdbc.password" value="test"/>
</properties>
</persistence-unit>
这是 Customer.java:
package com.newthinktank.JEETut3;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name ="customer")
public class Customer implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "custID", unique = true)
private int id;
@Column(name = "firstName", nullable = false)
private String fName;
@Column(name = "lastName", nullable = false)
private String lName;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getfName() {
return fName;
}
public void setfName(String fName) {
this.fName = fName;
}
public String getlName() {
return lName;
}
public void setlName(String lName) {
this.lName = lName;
}
}
我在构建路径和项目本身的类路径中包含了不同的 jars:hibernate-validation、java-persistence、hibernate-jpa 和 hibernate-entityManager。 我还在资源文件夹中复制了persistence.xml。 我做了很多事情,但它不起作用,总是出现相同的错误。
问题与 jars 或persistence.xml
位置无关。
文件persistence.xml
无效,因为<persistence ...>
未关闭。 问题可以通过在persistence.xml
末尾添加</persistence>
解决
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.