use of javax.persistence.EntityManager in project hibernate-orm by hibernate.
the class ExpressionsTest method prepareTestData.
@Before
public void prepareTestData() {
builder = entityManagerFactory().getCriteriaBuilder();
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Product product = new Product();
product.setId("product1");
product.setPrice(1.23d);
product.setQuantity(2);
product.setPartNumber(((long) Integer.MAX_VALUE) + 1);
product.setRating(1.999f);
product.setSomeBigInteger(BigInteger.valueOf(987654321));
product.setSomeBigDecimal(BigDecimal.valueOf(987654.32));
em.persist(product);
em.getTransaction().commit();
em.close();
}
use of javax.persistence.EntityManager in project hibernate-orm by hibernate.
the class CallbacksTest method testCallBackListenersHierarchy.
@Test
public void testCallBackListenersHierarchy() throws Exception {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Television tv = new Television();
em.persist(tv);
tv.setName("Myaio");
tv.init();
em.flush();
assertEquals(1, tv.counter);
em.getTransaction().rollback();
em.close();
assertEquals(5, tv.communication);
assertTrue(tv.isLast);
}
use of javax.persistence.EntityManager in project hibernate-orm by hibernate.
the class CallbacksTest method testIdNullSetByPrePersist.
@Test
public void testIdNullSetByPrePersist() throws Exception {
Plant plant = new Plant();
plant.setName("Origuna plantula gigantic");
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist(plant);
em.flush();
em.getTransaction().rollback();
em.close();
}
use of javax.persistence.EntityManager in project hibernate-orm by hibernate.
the class CascadeTest method testNoCascadeAndMerge.
@Test
public void testNoCascadeAndMerge() throws Exception {
Song e1 = new Song();
Author e2 = new Author();
e1.setAuthor(e2);
EntityManager em = getOrCreateEntityManager();
EntityTransaction tx = em.getTransaction();
tx.begin();
em.persist(e2);
em.persist(e1);
tx.commit();
em.close();
em = getOrCreateEntityManager();
e1 = em.find(Song.class, e1.getId());
tx = em.getTransaction();
tx.begin();
em.merge(e1);
//em.refresh(e1);
tx.commit();
em.close();
}
use of javax.persistence.EntityManager in project hibernate-orm by hibernate.
the class CascadeTest method testCascade.
@Test
public void testCascade() throws Exception {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Teacher teacher = new Teacher();
Student student = new Student();
teacher.setFavoriteStudent(student);
student.setFavoriteTeacher(teacher);
teacher.getStudents().add(student);
student.setPrimaryTeacher(teacher);
em.persist(teacher);
em.getTransaction().commit();
em = getOrCreateEntityManager();
em.getTransaction().begin();
Teacher foundTeacher = (Teacher) em.createQuery("select t from Teacher as t").getSingleResult();
System.out.println(foundTeacher);
System.out.println(foundTeacher.getFavoriteStudent());
for (Student fstudent : foundTeacher.getStudents()) {
System.out.println(fstudent);
System.out.println(fstudent.getFavoriteTeacher());
System.out.println(fstudent.getPrimaryTeacher());
}
// here *alot* of flushes occur on an object graph that has *Zero* changes.
em.getTransaction().commit();
em.close();
}
Aggregations