{"id":68,"date":"2016-10-26T15:01:24","date_gmt":"2016-10-26T15:01:24","guid":{"rendered":"http:\/\/codeinsightacademy.com\/cprogramming\/?p=68"},"modified":"2017-11-08T11:59:04","modified_gmt":"2017-11-08T11:59:04","slug":"hibernate-crud-with-mysql-database-java","status":"publish","type":"post","link":"https:\/\/codeinsightacademy.com\/blog\/java\/hibernate-crud-with-mysql-database-java\/","title":{"rendered":"Hibernate CRUD with MySQL Database &#8211; Java"},"content":{"rendered":"<p><iframe loading=\"lazy\" src=\"https:\/\/www.youtube.com\/embed\/Y_dixodZ1o0\" width=\"750\" height=\"315\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<p>&nbsp;<\/p>\n<p>To Update Record Using Hibernate Session:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\">Configuration cfg = new Configuration().configure(\"hibernate.cfg.xml\"); \r\n\r\nStandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder().applySettings(cfg.getProperties()); \r\n\r\nSessionFactory factory = cfg.buildSessionFactory(ssrb.build()); Session session = factory.openSession(); \r\n\r\nTransaction t = session.beginTransaction(); \r\n\r\nUsers u = (Users) session.load(Users.class, 6); \/\/ load record having id 6 into u object\r\n\r\nu.setLastName(\"Nitnavre\"); \/\/ set column value which needs to update\r\n\r\nSystem.out.println(session.save(u)); \/\/ fire update query using save function of hibernate\r\n\r\nt.commit(); \/\/ commit the update changes to save state in database\r\n\r\nSystem.out.println(\"Record updated successfully...\");<\/pre>\n<p>&nbsp;<\/p>\n<p>Ref Link:<\/p>\n<ol>\n<li>https:\/\/www.journaldev.com\/3481\/hibernate-session-merge-vs-update-save-saveorupdate-persist-example<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; To Update Record Using Hibernate Session: Configuration cfg = new Configuration().configure(&#8220;hibernate.cfg.xml&#8221;); StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder().applySettings(cfg.getProperties()); SessionFactory factory = cfg.buildSessionFactory(ssrb.build()); Session session = factory.openSession(); Transaction t = session.beginTransaction(); Users u = (Users) session.load(Users.class, 6); \/\/ load record having id 6 into u object u.setLastName(&#8220;Nitnavre&#8221;); \/\/ set column value which needs to update System.out.println(session.save(u)); \/\/ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[],"_links":{"self":[{"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/posts\/68"}],"collection":[{"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/comments?post=68"}],"version-history":[{"count":8,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/posts\/68\/revisions"}],"predecessor-version":[{"id":463,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/posts\/68\/revisions\/463"}],"wp:attachment":[{"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/media?parent=68"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/categories?post=68"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/tags?post=68"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}