java - Hibernate does not save Object even not getting any error in log -


i have single table in db . created pojo class map class instance table. class structure

   @entity     @table(name = "example")     class example {      @id         @generatedvalue(strategy = generationtype.auto)         @column(name = "id")         int id;         @column(name = "slot_id")         int slot_id;         @column(name = "slot_date")         string slot_date;         @column(name = "hotel_id")         string hotel_id;         @column(name = "room_type_id")         string room_type_id;         @column(name = "create_date")         string create_date;         @column(name = "update_date")         string update_date;         @column(name = "slot_price")         double slot_price;         @column(name = "available_rooms")         integer available_roooms;  //rest have getter , setter method } 

hibernet commit part

  public void save(example example) {          session session = null;         try {             log.info( example.tostring());             session = this.sessionfactory.opensession();             transaction tx = session.begintransaction();             session.persist(example);             tx.commit();          } catch (exception e) {             e.printstacktrace();         } {             session.close();         }     } 

in log getting log

hibernate: insert example(available_rooms, create_date, hotel_id, room_type_id, slot_date, slot_id, slot_price, update_date) values (?, ?, ?, ?, ?, ?, ?, ?) 

i able fetch data same table here code snap `

session = this.sessionfactory.opensession();  criteria cr = session.createcriteria(example.class); cr.add(restrictions.eq("id", id)); list results = cr.list();  if(results.size()>0)  return mapper.writevalueasstring(results.get(0)); //id auto //incremented in table` 

i dont see error in log when cheked in db no data has been inserted.any clue missed ?

use code , test once

public void save(example example) {     session session = null;     transaction tx=null;     try {         log.info( example.tostring());         session = this.sessionfactory.opensession();         tx = session.begintransaction();         session.persist(example);         tx.commit();      } catch (exception e) {         e.printstacktrace();     } {       if (!tx.wascommitted()) {      tx.rollback();      }//not doing practice      session.flush(); //this think things start working.      session.close();     } } 

good reason call flush before close here


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -