Why does the location of persist() affect the number of HQL requests?

Viewed 11

Why does the flash() consider intermediate instructions after persist()? I'm talking about case case 2, where a separate update request was made for setName.

// 1
@Transactional
public void persist1(){
    Post post = new Post();
    post.setName("name1");
    entityManager.persist(post);
}

// 2
@Transactional
public void persist2(){
    Post post = new Post();
    entityManager.persist(post);
    post.setName("name2");
}

// 1
Hibernate: insert into post (name, id) values (?, ?)

// 2
Hibernate: insert into post (name, id) values (?, ?)
Hibernate: update post set name=? where id=?
0 Answers
Related