{"id":2490,"date":"2017-10-01T07:23:48","date_gmt":"2017-10-01T07:23:48","guid":{"rendered":"http:\/\/codethataint.com\/blog\/?p=2490"},"modified":"2017-10-01T07:23:48","modified_gmt":"2017-10-01T07:23:48","slug":"difference-between-createquery-vs-createsqlquery-vs-createcriteria","status":"publish","type":"post","link":"https:\/\/codethataint.com\/blog\/difference-between-createquery-vs-createsqlquery-vs-createcriteria\/","title":{"rendered":"Difference between createQuery vs createSQLQuery vs createCriteria"},"content":{"rendered":"<table>\n<thead>\n<th>createQuery()<\/th>\n<th>createSQLQuery()<\/th>\n<th>createCriteria()<\/th>\n<\/thead>\n<tbody>\n<tr>\n<td>Creates Query Object<\/td>\n<td>Creates Query Object<\/td>\n<td>Creates Criteria Object<\/td>\n<\/tr>\n<tr>\n<td>Uses HQL Syntax<\/td>\n<td>Uses DB Specific Syntax<\/td>\n<td>Uses Entity Class<\/td>\n<\/tr>\n<tr>\n<td>The Columns of the rows retrieved would be name of the POJO Model Class<\/td>\n<td>The Columns of the rows retrieved would be name of Native DB fields<\/td>\n<td>Create sql query using Criteria object for setting the query parameters<\/td>\n<\/tr>\n<tr>\n<td>CRUD operation could be done<\/td>\n<td>CRUD operation could be done<\/td>\n<td>Only Read Operation is allowed<\/td>\n<\/tr>\n<tr>\n<td>Supports Interoperability between different DB&#8217;s<\/td>\n<td>Does not support Interoperability since the query format should be changed when the DB is changed<\/td>\n<td>Supports Interoperability between different DB&#8217;s<\/td>\n<\/tr>\n<tr>\n<td>Does not work without Model Class<\/td>\n<td>Bean with columns of Table alone is Enough.No need for Entity class generation<\/td>\n<td>Does not work without Model Class<\/td>\n<\/tr>\n<tr>\n<td>No need for mapping between Entity class object and Table Columns<\/td>\n<td>The Bean Objects should be mapped with table Columns<\/td>\n<td>No need for mapping <\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>createQuery &#8211; session.createQuery()<\/strong><\/p>\n<pre>\r\n------------------------------------------------------\r\n**DB_TBL_Col(tblEmployee)**| **POJO(Employee)**\r\nEMP_ID                     | employeeID\r\n------------------------------------------------------\r\n<\/pre>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\nQuery query = session.createQuery(&quot;from Employee E where E.employeeID = 'A%'&quot;);\r\nList&lt;Person&gt; persons = query.list();\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>createQuery() createSQLQuery() createCriteria() Creates Query Object Creates Query Object Creates Criteria Object Uses HQL Syntax Uses DB Specific Syntax Uses Entity Class The Columns of the rows retrieved would be name of the POJO Model Class The Columns of the rows retrieved would be name of Native DB fields Create sql query using Criteria object&hellip; <a href=\"https:\/\/codethataint.com\/blog\/difference-between-createquery-vs-createsqlquery-vs-createcriteria\/\">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-2490","post","type-post","status-publish","format-standard","hentry","category-hibernate"],"_links":{"self":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/2490","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=2490"}],"version-history":[{"count":1,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/2490\/revisions"}],"predecessor-version":[{"id":2492,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/2490\/revisions\/2492"}],"wp:attachment":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/media?parent=2490"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/categories?post=2490"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/tags?post=2490"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}