[英]XML document structures must start and end within the same entity
Getting the error while making a small project of inserting and retrieving data from database using technologies JAVA, JPA, MAVEN, MYSQL.使用 JAVA、JPA、MAVEN、MYSQL 技术制作从数据库插入和检索数据的小项目时出现错误。 Below is my code.下面是我的代码。
This is my persistence.xml code:这是我的 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>
This is Customer.java:这是 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;
}
}
I included different jars: hibernate-validation, java-persistence, hibernate-jpa and hibernate-entityManager in the build path and also class path of project itself.我在构建路径和项目本身的类路径中包含了不同的 jars:hibernate-validation、java-persistence、hibernate-jpa 和 hibernate-entityManager。 I also copied persistence.xml in resource folder.我还在资源文件夹中复制了persistence.xml。 I did lots of things, but it does not work, getting always the same error.我做了很多事情,但它不起作用,总是出现相同的错误。
Problem has nothing to do with jars or persistence.xml
location.问题与 jars 或persistence.xml
位置无关。
File persistence.xml
is invalid, because <persistence ...>
is not closed.文件persistence.xml
无效,因为<persistence ...>
未关闭。 Problem can be solved by adding </persistence>
to the end of the persistence.xml
问题可以通过在persistence.xml
末尾添加</persistence>
解决
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.