java - Getting same session object -


in simple hibernate program getting detail of employee table using following code. :- employee employee = (employee) session.get(employee.class, new integer(6)); , same time print information in console system.out.println("name : -"+employee.getname() + "address :- " + employee.getaddress());

now paused execution 15000 ms. thread.sleep(15000); during time go through database , manually change details of employee table. when 15000ms completed , clear session cache , again try fetch same record i'm getting same object having same information . whatever information change during sleep time not reflected.

below program

configuration configuration = new configuration();

configuration.configure("hibernate.cfg.xml"); serviceregistry registry = (serviceregistry) builder.buildserviceregistry(); builder.applysettings(configuration.getproperties()); serviceregistry registry = (serviceregistry) builder.buildserviceregistry(); factory = configuration.buildsessionfactory(registry);  session session = factory.opensession(); transaction transaction = session.begintransaction();  employee employee = (employee) session.get(employee.class, new integer(6)); system.out.println("name : -" + employee.getname() + "address :- " + employee.getaddress());  thread.sleep(15000); //now made change in database going through mysql workbench , manually change details of emp id 6.  system.out.println(" cache remove"); session.evict(employee); session.flush();  employee employee1 = (employee) session.get(employee.class, new integer(6)); system.out.println("name : -" + employee1.getname() + "address :- " + employee1.getaddress()); printemp(employee); session.gettransaction().commit(); session.close(); 

first ensure manual db changes getting reflected(commited) in db have started transaction.

check database isolation level. think program behaving per should be.

also can try use show sql option debugging.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -