I know this question has been out there for a while but I tried about 10 different solutions and nothing worked. I'm new to Hibernate and Maven, so I'm a bit lost.
I've checked if persistence is inside Meta-inf, added provider tag under persistence unit, checked libraries and so on...
import com.bookstore.entity.Users;
public class UsersTest {
public static void main(String[] args) {
Users user1 = new Users();
user1.setEmail("pablo.the.souza@gmail.com");
user1.setFullName("Pablo Souza");
user1.setPassword("123456");
EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("BookStoreWebsite");
EntityManager entityManager = entityManagerFactory.createEntityManager();
entityManager.getTransaction().begin();
entityManager.persist(user1);
entityManager.getTransaction().commit();
entityManager.close();
entityManagerFactory.close();
System.out.println("A users object was persisted");
}
}
<?xml version="1.0" encoding="UTF-8"?>
<persistence 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"
version="2.1">
<persistence-unit name="BookStoreWebsite">
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/bookstore" />
<property name="javax.persistence.jdbc.user" value="root" />
<property name="javax.persistence.jdbc.password" value="password" />
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
</properties>
</persistence-unit>
</persistence>