package org.hibernate.bugs;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
/**
* This template demonstrates how to develop a test case for Hibernate ORM, using the Java
* Persistence API.
*/
public class JPAUnitTestCase {
private EntityManagerFactory entityManagerFactory;
@Before
public void init() {
entityManagerFactory = Persistence.createEntityManagerFactory("templatePU");
}
@After
public void destroy() {
entityManagerFactory.close();
}
@Test
public void hhh123Test() throws Exception {
EntityManager entityManager = entityManagerFactory.createEntityManager();
entityManager.getTransaction().begin();
String primaryKey = "chewing gum";
Product product1 = new Product(primaryKey);
product1.setPrice("France", 100);
entityManager.persist(product1);
entityManager.getTransaction().commit();
entityManager.clear();
entityManager.getTransaction().begin();
Product product2 = entityManager.find(Product.class, primaryKey);
product2.setPrice("France", 999);
entityManager.getTransaction().commit();
entityManager.getTransaction().begin();
Product product3 = entityManager.find(Product.class, primaryKey);
long actual = product3.getPrice("France");
entityManager.getTransaction().commit();
Assert.assertEquals(999L, actual);
entityManager.close();
}
}