简体   繁体   中英

javax.persistence.PersistenceException: No Persistence provider for EntityManager named aramis

I am new to JPA and Hibernate. I am watching tutorials and I did every did everything mentioned from videos but I thought some errors.

I am working with eclipse java ee. And jpa,hibernate,MySQL

persistance:

<?xml version="1.0" encoding="UTF-8"?>
    <persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
        <persistence-unit name="aramis" transaction-type="RESOURCE_LOCAL">
            <provider>org.hibernate.ejb.HibernatePersistence</provider>
            <class>com.webproject.web.entities.User</class>
            <properties>
                <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/webproject" />
                <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
                <property name="hibernate.connection.username" value="root" />
                <property name="hibernate.connection.password" value="mysql123" />
            </properties>
        </persistence-unit>
    </persistence>

user:

@Entity(name="user")
    @Table(name="user")
    public class User implements Serializable {

        @Id
        @GeneratedValue(strategy=GenerationType.AUTO)
        @Column(name="id", updatable = false, nullable = false)
        private int id;

        private String name;

        @Column(nullable=false, unique=true)
                  ...

service: public class UserService {

    private EntityManagerFactory emf = Persistence.createEntityManagerFactory("aramis");
    private EntityManager em = emf.createEntityManager();
    private EntityTransaction tx = em.getTransaction();

    private Sha512 sha512 = new Sha512();


    public int insert(User user) {
        Date date = new Date();
        user.setCreated_at(date);
        user.setRole_type(0);

        String password = user.getPassword();
        password = sha512.encrypt(password);
        user.setPassword(password);

        tx.begin();
        em.persist(user);
        tx.commit();
        em.close();

        return user.getId();
    }

it's giving some error:

javax.persistence.PersistenceException: No Persistence provider for EntityManager named aramis
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:61)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
at com.webproject.web.services.UserService.<init>(UserService.java:19)
at com.webproject.web.servlet.Register.doPost(Register.java:54)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)

also my paths: path

When you call Persistence.createEntityManagerFactory("aramis") by default it's trying to find a file called persistence.xml inside a folder called META-INF .

In order to make it work, you should have a META-INF/persistence.xml in your classpath.

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