I am trying to try the code to save student information in hibernate session.save (). In this, student name, class, teacher identifier.
Table: Student
SNO SNAME SCLASS TNO
----------- ----------------------------------------
1 J D Alex 3 1
2 Goaty 2 2
3 J D Paul 7 1
The code: -
Transaction tx1=session1.beginTransaction();
Object o2=session1.get(Student.class,new Integer(3));
((Student)o2).setSclass("8");
session1.save(o2);
log.info("loadStdYearlyInfo:class "+((Student)o2).getSclass());
tx1.commit();
session1.close();
After saving the data and viewing the result, the class value is updated as 8 for student ID 3
SNO SNAME SCLASS TNO
1 J D Alex 3 1
2 Goaty 2 2
3 J D Paul 8 1
[07/May/2012:10:03:06] info ( 3500): CORE3282: stdout: Hibernate: select student0_.sno as sno0_, student0_.sname as sname1_0_, student0_.sclass as sclass1_0_, student0_.tno as tno1_0_ from student student0_ where student0_.sno=?
[07/May/2012:10:03:06] info ( 3500): CORE3282: stdout: loadStdYearlyInfo:class 8
[07/May/2012:10:03:06] info ( 3500): CORE3282: stdout: Hibernate: update student set sname=?, sclass=?, tno=? where sno=?
[07/May/2012:10:03:06] info ( 3500): CORE3282: stdout: loadStdYearlyInfo2
How does the updated student class value in the database? .Save mean insert data. But here the value is updated. Please let me know. If you have any problems?. If any question was sorry.
source
share