Session saveorupdate not updating

I am not sure why the above code creates a new row in tables it should update in both cases to my understanding, Any idea what could I be missing?Or what info will you need to help me track the problem...

session saveorupdate not updating-76session saveorupdate not updating-90

This is the major difference with merge() from all other methods. package com.journaldev.hibernate.main; import org.hibernate.

This confirms that hibernate was tracking the object for any changes and at the time of committing transaction, this value got saved. Hibernate Util; public class Hibernate Merge Example Hibernate: select employee0_.emp_id as emp_id1_1_0_, employee0_.emp_name as emp_name2_1_0_, employee0_.emp_salary as emp_sala3_1_0_, address1_.emp_id as emp_id1_0_1_, address1_.address_line1 as address_2_0_1_, address1_as city3_0_1_, address1_.zipcode as zipcode4_0_1_ from EMPLOYEE employee0_ left outer join ADDRESS address1_ on employee0_.emp_id=address1_.emp_id where employee0_.emp_id=? Id= 101, Name= Final updated name, Salary= 1000.0, false 15.

Also notice the employee name is “Final updated name” that we set after invoking update() method. After committing merge transaction Hibernate: select employee0_.emp_id as emp_id1_1_0_, employee0_.emp_name as emp_name2_1_0_, employee0_.emp_salary as emp_sala3_1_0_, address1_.emp_id as emp_id1_0_1_, address1_.address_line1 as address_2_0_1_, address1_as city3_0_1_, address1_.zipcode as zipcode4_0_1_ from EMPLOYEE employee0_ left outer join ADDRESS address1_ on employee0_.emp_id=address1_.emp_id where employee0_.emp_id=?

If we use this without transaction and we have cascading between entities, then only the primary entity gets saved unless we flush the session.

package com.journaldev.hibernate.model; import javax.persistence.

Leave a Reply