{"id":513,"date":"2014-08-06T15:03:06","date_gmt":"2014-08-06T15:03:06","guid":{"rendered":"http:\/\/codethataint.com\/blog\/?p=513"},"modified":"2014-08-06T16:16:55","modified_gmt":"2014-08-06T16:16:55","slug":"hibernate-config-file-for-mysql-dialect","status":"publish","type":"post","link":"https:\/\/codethataint.com\/blog\/hibernate-config-file-for-mysql-dialect\/","title":{"rendered":"Hibernate Config File for MySQL Dialect"},"content":{"rendered":"<p>Defining Dialect in Hibernate<\/p>\n<figure id=\"attachment_515\" class=\"wp-caption thumbnail alignnone\" style=\"width: 580px;\">\n\t\t\t\t<a href=\"http:\/\/codethataint.com\/blog\/wp-content\/uploads\/2014\/08\/2.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/codethataint.com\/blog\/wp-content\/uploads\/2014\/08\/2-580x328.png\" alt=\"MySQL Dialect\" width=\"580\" height=\"328\" class=\"size-medium wp-image-515\" srcset=\"https:\/\/codethataint.com\/blog\/wp-content\/uploads\/2014\/08\/2-580x328.png 580w, https:\/\/codethataint.com\/blog\/wp-content\/uploads\/2014\/08\/2-940x532.png 940w, https:\/\/codethataint.com\/blog\/wp-content\/uploads\/2014\/08\/2.png 1069w\" sizes=\"auto, (max-width: 580px) 100vw, 580px\" \/><\/a>\n\t\t\t\t<figcaption class=\"wp-caption-text\">MySQL Dialect<\/figcaption>\n\t\t\t<\/figure>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n\r\n&lt;!DOCTYPE hibernate-configuration PUBLIC\r\n        &quot;-\/\/Hibernate\/Hibernate Configuration DTD 3.0\/\/EN&quot;\r\n        &quot;http:\/\/www.hibernate.org\/dtd\/hibernate-configuration-3.0.dtd&quot;&gt;\r\n&lt;hibernate-configuration&gt;  \r\n    &lt;session-factory&gt;\r\n        &lt;property name=&quot;connection.driver_class&quot;&gt;com.mysql.jdbc.Driver&lt;\/property&gt;\r\n        &lt;property name=&quot;connection.url&quot;&gt;jdbc:mysql:\/\/localhost:3306\/hibernate&lt;\/property&gt;\r\n        &lt;property name=&quot;connection.username&quot;&gt;root&lt;\/property&gt;\r\n        &lt;property name=&quot;connection.password&quot;&gt;pass&lt;\/property&gt;\r\n        \r\n        &lt;!-- JDBC connection pool (use the built-in) --&gt;\r\n        &lt;property name=&quot;connection.pool_size&quot;&gt;1&lt;\/property&gt;\r\n\r\n        &lt;!-- SQL dialect --&gt;\r\n        &lt;property name=&quot;dialect&quot;&gt;org.hibernate.dialect.MySQLDialect&lt;\/property&gt;\r\n\r\n        &lt;!-- Disable the second-level cache  --&gt;\r\n        &lt;property name=&quot;cache.provider_class&quot;&gt;org.hibernate.cache.internal.NoCacheProvider&lt;\/property&gt;\r\n\r\n        &lt;!-- Echo all executed SQL to stdout --&gt;\r\n        &lt;property name=&quot;show_sql&quot;&gt;true&lt;\/property&gt;\r\n\r\n        &lt;!-- Drop and re-create the database schema on startup --&gt;\r\n        &lt;property name=&quot;hbm2ddl.auto&quot;&gt;update&lt;\/property&gt;\r\n        \r\n        &lt;!-- Name of the Annotated Entity class --&gt;\r\n        &lt;mapping class=&quot;com.mugil.dto.UserDetails&quot;\/&gt;\r\n    &lt;\/session-factory&gt;\r\n&lt;\/hibernate-configuration&gt;\r\n<\/pre>\n<p>If <strong>hbm2ddl.auto<\/strong> is set to create the table will be created every time when java class is Run.The old records will be deleted.<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n&lt;property name=&quot;hbm2ddl.auto&quot;&gt;create&lt;\/property&gt;\r\n<\/pre>\n<p>When set to update the records will be added without new table creation <\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n&lt;property name=&quot;hbm2ddl.auto&quot;&gt;update&lt;\/property&gt;\r\n<\/pre>\n<p><strong>More Annotations<\/strong><\/p>\n<p><a href=\"http:\/\/codethataint.com\/blog\/wp-content\/uploads\/2014\/08\/3.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/codethataint.com\/blog\/wp-content\/uploads\/2014\/08\/3.png\" alt=\"3\" width=\"415\" height=\"469\" class=\"alignnone size-full wp-image-519\" \/><\/a><\/p>\n<p>@Transient tells not to create Column<br \/>\n@Column tells the Hibernate the Name under which column need to be<br \/>\ncreated in Db table.<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n@Transient \r\n@Column (name=&quot;User_Name&quot;) \r\nprivate String userName; \r\n<\/pre>\n<p>@Temporal tells the option of selective addition.Below I am adding Date rather than<br \/>\nDate &#038; time as Timestamp<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n @Temporal (TemporalType.DATE) \r\n private Date DOJ;\r\n<\/pre>\n<p>@Lob &#8211; Large Object, Telling Hibernate to create Large Object Datatype fro Column<br \/>\n@Lob over String creates CLOB<br \/>\n@Lob over Byte creates BLOB<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n @Lob\r\n private String userDescription;\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Defining Dialect in Hibernate &lt;!DOCTYPE hibernate-configuration PUBLIC &quot;-\/\/Hibernate\/Hibernate Configuration DTD 3.0\/\/EN&quot; &quot;http:\/\/www.hibernate.org\/dtd\/hibernate-configuration-3.0.dtd&quot;&gt; &lt;hibernate-configuration&gt; &lt;session-factory&gt; &lt;property name=&quot;connection.driver_class&quot;&gt;com.mysql.jdbc.Driver&lt;\/property&gt; &lt;property name=&quot;connection.url&quot;&gt;jdbc:mysql:\/\/localhost:3306\/hibernate&lt;\/property&gt; &lt;property name=&quot;connection.username&quot;&gt;root&lt;\/property&gt; &lt;property name=&quot;connection.password&quot;&gt;pass&lt;\/property&gt; &lt;!&#8211; JDBC connection pool (use the built-in) &#8211;&gt; &lt;property name=&quot;connection.pool_size&quot;&gt;1&lt;\/property&gt; &lt;!&#8211; SQL dialect &#8211;&gt; &lt;property name=&quot;dialect&quot;&gt;org.hibernate.dialect.MySQLDialect&lt;\/property&gt; &lt;!&#8211; Disable the second-level cache &#8211;&gt; &lt;property name=&quot;cache.provider_class&quot;&gt;org.hibernate.cache.internal.NoCacheProvider&lt;\/property&gt; &lt;!&#8211; Echo all executed SQL to stdout &#8211;&gt; &lt;property&hellip; <a href=\"https:\/\/codethataint.com\/blog\/hibernate-config-file-for-mysql-dialect\/\">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-513","post","type-post","status-publish","format-standard","hentry","category-hibernate"],"_links":{"self":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/513","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=513"}],"version-history":[{"count":6,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/513\/revisions"}],"predecessor-version":[{"id":517,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/513\/revisions\/517"}],"wp:attachment":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/media?parent=513"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/categories?post=513"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/tags?post=513"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}