Hibernate Data not updating in database -


i using hibernate 3 in application there 1 scenario inserting 2 record , updating 1 record :-

  sessionfactory sf = hibernateutils.getsessionfactory();         session = sf.opensession();         tx = session.begintransaction();         collection collection = session.load(collection.class, "12345");             tx.commit(); // using way getting object database.  setcollection(collection);//here setting object in 1 pojo class 

now in other function

i getting object again...

collection collection=getcollection(); //here detached 

now here first saving data in 1 table using below approach:-

 sessionfactory sf = hibernateutils.getsessionfactory();             session = sf.opensession();             tx = session.begintransaction();     sms sms=new sms();         sms.setmessage(collection.getmesage());        session.save(sms);        tx.commit();        session.flush();        session.close(); 

then updating , inserting 2 records in same session

sessionfactory sf = hibernateutils.getsessionfactory();             session = sf.opensession();             tx = session.begintransaction();     cancel cancel=new cancel();         cancel.setmessage(collection.getmesage());        session.save(cancel);        session.update(collection);        tx.commit();        session.flush();        session.close(); 

the problem in above code , here in sms , in cancel table data saving update not working , not showing error also.

its not happening in every case, sometime not updating

is there problem 2 different sessions ??

no there nothing wrong in taking 2 different session.

here happening in code:

first getting object database , closing session

collection collection=opensession(); session.load()....session.close();

then setting collection object. setcollection(collection);

now act detached object. if transaction.commit after object committed in database saving other object, doing in first part saving first object.

in second transaction there nothing update not getting updated.


Comments