I am testing hibernate and giving this query to
transaction = session.beginTransaction();
city = new City("A");
city = (City)session.merge(city);
city.setName("B");
transaction.commit();
And I am getting those queries in the command line:
Hibernate: insert into CITY (name) values (?)
Hibernate: update CITY set name=? where CITY_ID=?
I am using merge not save, so why hibernate is updating my object, It should not update. am it right? What is the mistake?
I will try to explain using a more concrete example. Suppose you have a scenario like below :
Exception when an attempt to reattach a Detached object, userA is made.
To get around the above problem, merge() is used, as shown below :