This is the code :
Alien alien = session.get(Alien.class, 4);
session.clear();
alien.setTech(“Software11”);
session.saveOrUpdate(alien);
This fires :
Hibernate: select alien0_.aid
as aid1_0_0_, alien0_.name
as name2_0_0_, alien0_.tech
as tech3_0_0_ from Alien
alien0_ where alien0_.aid
=?
Hibernate: select alien_.aid
, alien_.name
as name2_0_, alien_.tech
as tech3_0_ from Alien
alien_ where alien_.aid
=?
Hibernate: update Alien
set name
=?, tech
=? where aid
=?
For update method :
Alien alien = session.get(Alien.class, 4);
session.clear();
alien.setTech(“Software22”);
session.update(alien);
This fires :
Hibernate: select alien0_.aid
as aid1_0_0_, alien0_.name
as name2_0_0_, alien0_.tech
as tech3_0_0_ from Alien
alien0_ where alien0_.aid
=?
Hibernate: update Alien
set name
=?, tech
=? where aid
=?
Only one query for update which also should hit database as entity is detached and saveOrUpdate does 2 query for same reason why?