{"id":522,"date":"2014-08-13T02:38:19","date_gmt":"2014-08-13T02:38:19","guid":{"rendered":"http:\/\/codethataint.com\/blog\/?p=522"},"modified":"2014-08-13T02:42:39","modified_gmt":"2014-08-13T02:42:39","slug":"how-to-retrieve-value-from-database-using-session-hibernate","status":"publish","type":"post","link":"https:\/\/codethataint.com\/blog\/how-to-retrieve-value-from-database-using-session-hibernate\/","title":{"rendered":"How to retrieve value from Database using session Hibernate"},"content":{"rendered":"<p><strong>Retrieve value from Database using Session <\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npublic static void main(String&#x5B;] args)\r\n{\r\n\tUserDetails objUserDetail =  new UserDetails();\r\n\t.\r\n\tsession.getTransaction().commit();\r\n\r\n\tobjUserDetail = null;\r\n\r\n\t\/*Retriving UserDetails from DB Using Session*\/\r\n\tsession = sessionFact.openSession();\r\n\tsession.beginTransaction();\r\n\tobjUserDetail = (UserDetails)session.get(UserDetails.class, 105);\r\n\tSystem.out.println(objUserDetail.getUserName());\r\n}\r\n<\/pre>\n<p>To retrieve the value from session we use the primary key for the table in the above case.<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n objUserDetail = (UserDetails)session.get(UserDetails.class, 105);\r\n System.out.println(objUserDetail.getUserName());\r\n<\/pre>\n<p>105 &#8211; is the UserId which is primary key for the USER_DETAILS table in DB.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Retrieve value from Database using Session public static void main(String&#x5B;] args) { UserDetails objUserDetail = new UserDetails(); . session.getTransaction().commit(); objUserDetail = null; \/*Retriving UserDetails from DB Using Session*\/ session = sessionFact.openSession(); session.beginTransaction(); objUserDetail = (UserDetails)session.get(UserDetails.class, 105); System.out.println(objUserDetail.getUserName()); } To retrieve the value from session we use the primary key for the table in the above&hellip; <a href=\"https:\/\/codethataint.com\/blog\/how-to-retrieve-value-from-database-using-session-hibernate\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[74],"tags":[],"class_list":["post-522","post","type-post","status-publish","format-standard","hentry","category-hibernate"],"_links":{"self":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/522","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/comments?post=522"}],"version-history":[{"count":5,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/522\/revisions"}],"predecessor-version":[{"id":527,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/522\/revisions\/527"}],"wp:attachment":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/media?parent=522"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/categories?post=522"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/tags?post=522"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}