Java Hibernate.merge may in any circunstance return null? -
hello have snippet this.
public void update(student student) { student=super.merge(student); currentsession().update(student); return; } but code throws
java.lang.illegalargumentexception: attempt create saveorupdate event null entity. i wondering how possible merge may return null in circunstance?
because have checked student not null because if null merge throw.
exception in thread "main" java.lang.illegalargumentexception: attempt create merge event null entity the situation think happening stuff if merge returning null possible??
sorry if question simple lot best regards venezuela..
merge() used merge detached object attached object (both have same id). example, passed in student1 object in method update(), has id , status detached:
public void update(student student1) { //student1 in detached status, may modify if not yet done student1.setname("abc"); //now load student2 db same id, note student2 in persistent status student student2 = currentsession().load(student.class, student1.getid()); //merge student1 student2 , return new student3 student student3 = currentsession().merge(student1); //--done, checkout student3, see "abc" merged. can't call update() in case. return; } if want update passed in student, remove student=super.merge(student);, call saveorupdate(), this:
public void update(student student) { currentsession().saveorupdate(student); return; }
Comments
Post a Comment