java - how save and perist method works in hibernate -
hello trying understand behavior of save , persist method of hibernate. write simple method , try run transaction , out transaction confused me.
@test public void saveorpersist() { person person = new person(); person.setfirstname("naveen"); person.setlastname("kumar"); // 1 session.begintransaction(); session.persist(person); // 2 session.save(person); // 3 session.flush(); // 4 session.gettransaction().commit(); }
with method did following things. uncomment line 1, 2 , 4 , comment line above line 2 test behavior of save method. works fine , give me following out on eclipse console.
hibernate: select nextval ('hibernate_sequence') hibernate: insert baseentity (createdatetime, description, updatedatetime, firstname, lastname, discriminator, id) values (?, ?, ?, ?, ?, 'p', ?)
also check db , 1 more entry inserted person table. second comment line 1 , line 4 again run same test case transaction. gives me below out put
hibernate: select nextval ('hibernate_sequence')
this time there no entry person table.
then did same thing persist method. run persist method twice transaction , without transaction , got same result on eclipse console.
now question apart return type there 1 more difference between persist , save. persist method not work out side of transaction. trying learn thing. can tell what's wrong concept or understood wrongly. if correct code little bit more description. in advance.
Comments
Post a Comment