Hey...nao estou conseguindo cadastrar o produto, alguém pode me ajudar?
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.2"
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_2.xsd">
<persistence-unit name="store" transaction-type="RESOURCE_LOCAL">
<properties>
<property name="javax.persistence.jdbc.driver" value="org.h2.Driver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:store"/>
<property name="javax.persistence.jdbc.user" value="sa"/>
<property name="javax.persistence.jdbc.password" value=""/>
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
<property name="hibernate.show.sql" value="true"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
</properties>
</persistence-unit>
</persistence>
package br.com.alura.store.model;
import javax.persistence.*;
import java.math.BigDecimal;
@Entity
@Table(name = "products")
public class Product {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
private String name;
private String description;
private BigDecimal price;
//Getters
public long getId() {
return id;
}
public String getName() {
return name;
}
public String getDescription() {
return description;
}
public BigDecimal getPrice() {
return price;
}
//Setter
public void setId(long id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
public void setDescription(String description) {
this.description = description;
}
public void setPrice(BigDecimal price) {
this.price = price;
}
}
package br.com.alura.store.test;
import br.com.alura.store.model.Product;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import java.math.BigDecimal;
public class ProductRegister {
public static void main(String[] args) {
Product phone = new Product();
phone.setName("Iphone");
phone.setDescription("Phone 13");
phone.setPrice(new BigDecimal("15000"));
EntityManagerFactory factory = Persistence
.createEntityManagerFactory("store");
EntityManager em = factory.createEntityManager();
em.getTransaction().begin();
em.persist(phone);
em.getTransaction().commit();
em.close();
}
}