verwaltete Entitätsinstanz X' erstellt und der Status von X wird in die kopiert Neue verwaltete Entitätsinstanz >
Code: Select all
entityManager.getTransaction().begin();
//let's assume we dont have a employee with id 2 in database
Employee e=new Employee();
e.setId(2);
e.setName("john");
/*
If I understand correctly the below query should run just an INSERT query
when context is flushed
but hibernate runs two queries,SELECT followed by INSERT
*/
entityManager.merge(e);
// entityManager.getTransaction().commit();
Code: Select all
entityManager.getTransaction().begin();
//let's assume we have a employee with id 3 in database
Employee e=new Employee();
e.setId(3);
e.setName("arthur");
/*
If I understand correctly the below query should fail to run because
then we would have two records with same primary key when context is flushed
but hibernate runs two queries,SELECT followed by UPDATE
*/
entityManager.merge(e);
// entityManager.getTransaction().commit();