简体   繁体   中英

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. Below is my code.

This is my persistence.xml code:

<?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:

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. I also copied persistence.xml in resource folder. 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.

File persistence.xml is invalid, because <persistence ...> is not closed. Problem can be solved by adding </persistence> to the end of the persistence.xml

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM