{"id":528,"date":"2014-08-13T14:11:52","date_gmt":"2014-08-13T14:11:52","guid":{"rendered":"http:\/\/codethataint.com\/blog\/?p=528"},"modified":"2014-08-13T14:12:56","modified_gmt":"2014-08-13T14:12:56","slug":"how-to-add-primary-key-to-table-hibernate","status":"publish","type":"post","link":"https:\/\/codethataint.com\/blog\/how-to-add-primary-key-to-table-hibernate\/","title":{"rendered":"How to Add Primary Key to table Hibernate"},"content":{"rendered":"<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n  @Id @GeneratedValue(strategy=GenerationType.AUTO)\r\n  private int userId;\r\n<\/pre>\n<p>By using <strong>@GeneratedValue<\/strong> annotation we can create primary key in table.The annotations takes 4 parameter as strategy attribute.<\/p>\n<p><strong>@GeneratedValue(strategy=GenerationType.AUTO)<\/strong><br \/>\nAuto tells the Hibernate to do the primary key addition from hibernate side<\/p>\n<p><strong>@GeneratedValue(strategy=GenerationType.IDENTITY)<\/strong><br \/>\nIDENTITY tells the Hibernate to do the primary key addition from DB side when set to auto increment.<\/p>\n<p><strong>@GeneratedValue(strategy=GenerationType.SEQUENCE)<\/strong><br \/>\nSEQUENCE tells the Hibernate to do the primary key addition as defined by sequence in DB.<\/p>\n<p><strong>@GeneratedValue(strategy=GenerationType.TABLE)<\/strong><br \/>\nTABLE tells the Hibernate to create a seperate table in DB and maintain the last inserted values.<br \/>\nThe table contains only one row with last inserted value.<\/p>\n<p><a href=\"http:\/\/codethataint.com\/blog\/wp-content\/uploads\/2014\/08\/15.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/codethataint.com\/blog\/wp-content\/uploads\/2014\/08\/15-580x74.png\" alt=\"15\" width=\"580\" height=\"74\" class=\"alignnone size-medium wp-image-529\" srcset=\"https:\/\/codethataint.com\/blog\/wp-content\/uploads\/2014\/08\/15-580x74.png 580w, https:\/\/codethataint.com\/blog\/wp-content\/uploads\/2014\/08\/15.png 701w\" sizes=\"auto, (max-width: 580px) 100vw, 580px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>@Id @GeneratedValue(strategy=GenerationType.AUTO) private int userId; By using @GeneratedValue annotation we can create primary key in table.The annotations takes 4 parameter as strategy attribute. @GeneratedValue(strategy=GenerationType.AUTO) Auto tells the Hibernate to do the primary key addition from hibernate side @GeneratedValue(strategy=GenerationType.IDENTITY) IDENTITY tells the Hibernate to do the primary key addition from DB side when set to auto&hellip; <a href=\"https:\/\/codethataint.com\/blog\/how-to-add-primary-key-to-table-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-528","post","type-post","status-publish","format-standard","hentry","category-hibernate"],"_links":{"self":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/528","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=528"}],"version-history":[{"count":2,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/528\/revisions"}],"predecessor-version":[{"id":531,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/528\/revisions\/531"}],"wp:attachment":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/media?parent=528"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/categories?post=528"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/tags?post=528"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}