简体   繁体   English

线程“主”中的异常javax.persistence.PersistenceException:名为jpa-test的EntityManager的持久性提供程序没有

[英]Exception in thread “main” javax.persistence.PersistenceException: No Persistence provider for EntityManager named jpa-test

My error text: 我的错误文字:

Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named jpa-test

I have tried all the ideas on this question from here but is not working. 我从这里尝试了所有关于此问题的想法,但是没有用。 I still get same error. 我仍然遇到相同的错误。 I dont know what to do..Please dont give me links to questions like this. 我不知道该怎么办..请不要给我链接到这样的问题。 I really tried all the ideas but still not working persistence.xml 我真的尝试了所有想法,但仍然无法运行persistence.xml

<?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="jpa-test" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <class>com.licenta.ascourses.model.Utilizator</class>
    <properties>
      <property name="javax.persistence.jdbc.driver" value="org.sqlite.JDBC" />
      <property name="javax.persistence.jdbc.url" value="jdbc:sqlite:test.db" />
      <property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
      <property name="eclipselink.ddl-generation.output-mode" value="database" />
    </properties>
    </persistence-unit>
</persistence>

Entity: 实体:

   package com.licenta.ascourses.model;

import java.io.Serializable;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

@Entity
public class Utilizator implements Serializable {

    @Id @GeneratedValue(strategy=GenerationType.AUTO)
    private int id_utilizator;
    private String username;
    private String parola;
    private String email;
    private String nume;
    private String prenume;
    private int cod;
    private int status;

    public Utilizator(String nume, String prenume){
        this.nume=nume;
        this.prenume=prenume;

    }



    public Utilizator(String username, String parola, String email, String nume,
            String prenume, int cod, int status) {


        this.username = username;
        this.parola = parola;
        this.email = email;
        this.nume = nume;
        this.prenume = prenume;
        this.cod = cod;
        this.status = status;
    }

    public Utilizator(String email, String nume, String prenume, int status) {
        super();
        this.email = email;
        this.nume = nume;
        this.prenume = prenume;
        this.status = status;
    }



    public Utilizator(String string) {
        this.username=string;
    }



    public int getId_utilizator() {
        return id_utilizator;
    }

    public void setId_utilizator(int id_utilizator) {
        this.id_utilizator = id_utilizator;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getParola() {
        return parola;
    }

    public void setParola(String parola) {
        this.parola = parola;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getNume() {
        return nume;
    }

    public void setNume(String nume) {
        this.nume = nume;
    }

    public String getPrenume() {
        return prenume;
    }

    public void setPrenume(String prenume) {
        this.prenume = prenume;
    }

    public int getCod() {
        return cod;
    }

    public void setCod(int cod) {
        this.cod = cod;
    }

    public int isStatus() {
        return status;
    }

    public void setStatus(int status) {

        this.status = (status==1)?1:0;


    }

    public int getStatus() {


        return (this.status==1)?1:0;

    }

}

My test class: 我的测试课:

package com.licenta.ascourses.DbConnection;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
import javax.persistence.Query;

import com.licenta.ascourses.model.Utilizator;

public class JPATest {

    public static void performJPA() {

        // Creating objects representing some products
        Utilizator user1=new Utilizator("andrei", "parola", "jean@jean", "jean", "popescu", 123, 1);
        Utilizator user2=new Utilizator("miu", "parola2", "ana@ana", "ana", "cartianu", 234, 1);

        // Connecting to the database through EntityManagerFactory
        // connection details loaded from persistence.xml
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("jpa-test");

        EntityManager em = emf.createEntityManager();

        // Creating a new transaction
        EntityTransaction tx = em.getTransaction();

        tx.begin();

        // Persisting the product entity objects
        em.persist(user1);
        em.persist(user2);

        tx.commit();

        // Querying the contents of the database using JPQL query
        Query q = em.createQuery("SELECT * FROM Utilizatori p");

        @SuppressWarnings("unchecked")
        List<Utilizator> results = q.getResultList();

        System.out.println("List of products\n----------------");

        for (Utilizator user : results) {

            System.out.println(user.getNume() + " (id=" + user.getId_utilizator() + ")");
        }

        // Closing connection
        em.close();

        emf.close();
    }




}

You need a JPA provider in your classpath. 您的类路径中需要一个JPA提供程序。 Example providers: Hibernate, Toplink, Apache OpenJPA, EclipseLink. 提供程序示例: Hibernate,Toplink,Apache OpenJPA,EclipseLink。

To learn about Java's classpath, see: Java Tutorial on Classpath 要了解Java的类路径,请参阅: 关于类路径的Java教程

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 线程“ main”中的异常javax.persistence.PersistenceException:没有名为EntityTest的EntityManager的持久性提供程序 - Exception in thread “main” javax.persistence.PersistenceException: No Persistence provider for EntityManager named databaseTest 线程“ main”中的异常javax.persistence.PersistenceException:名为lanceurApplication的EntityManager的持久性提供程序没有 - Exception in thread “main” javax.persistence.PersistenceException: No Persistence provider for EntityManager named lanceurApplication 具有Java SE的JPA:javax.persistence.PersistenceException:EntityManager没有持久性提供程序 - JPA with Java SE: javax.persistence.PersistenceException: No Persistence provider for EntityManager javax.persistence.PersistenceException:名为aramis的EntityManager的持久性提供程序 - javax.persistence.PersistenceException: No Persistence provider for EntityManager named aramis javax.persistence.PersistenceException:没有名为customerManager的EntityManager的持久性提供程序 - javax.persistence.PersistenceException: No Persistence provider for EntityManager named customerManager javax.persistence.PersistenceException:没有名为EntityManager的持久性提供程序 - javax.persistence.PersistenceException: No Persistence provider for EntityManager named javax.persistence.PersistenceException:没有名为EntityManager的持久性提供程序 - javax.persistence.PersistenceException: No Persistence provider for EntityManager named javax.persistence.PersistenceException:EntityManager 没有持久性提供程序 - javax.persistence.PersistenceException: No Persistence provider for EntityManager 持久性单元错误:javax.persistence.PersistenceException:没有命名 EntityManager 的持久性提供程序 - Persistence unit error: javax.persistence.PersistenceException: No Persistence provider for EntityManager named jboss 7.0.1休眠javax.persistence.PersistenceException:EntityManager没有持久性提供程序 - jboss 7.0.1 hibernate javax.persistence.PersistenceException: No Persistence provider for EntityManager
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM