java developer java developer - 1 year ago 102
Java Question

difference between entitymanager merge and execute update

What is the difference between


I have one entity order

@Table(name="ORDERS",schema ="AMZ")
public class Orders {

@SequenceGenerator(name = "pk_sequence", sequenceName = "ORDERS_SEQ", schema = "AMZ", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "pk_sequence")
@Column(name = "ORDERS_ID")
private long id;

@Column(name = "STATUS")
private Status status;

I have my DAO class

public class InvoiceDAO {

private EntityManager entityManager;

public void update(Order order){
mergeInvoice(Order order);

public void updateInvoice(){
entitymanager.createQuery("update Orders set status = 'ERROR' where id=12").executeUpdate();

public void mergeInvoice(Order order){


In the above, merge happens before
even though there are several transactions in between execute update is the last transaction which occurs. WHY?

I tried
but it didn't work.

Answer Source

I resolved this by calling the update and merge methods from service layer. I found that for the transaction to get commit I have to return out of my DAO.

public void update(Order order){
orderDao.mergeInvoice(Order order);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download