{"id":834,"date":"2010-06-07T17:16:16","date_gmt":"2010-06-07T11:46:16","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=834"},"modified":"2016-12-19T15:06:05","modified_gmt":"2016-12-19T09:36:05","slug":"how-to-change-sql-datatype-for-grails-domain-string-fields","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/how-to-change-sql-datatype-for-grails-domain-string-fields\/","title":{"rendered":"Change SQL datatype for Grails domain String fields"},"content":{"rendered":"<p>The Grails automatically identifies what should be the datatype of the field in sql table e.g; fields with String datatype are converted to varchar(255), but sometimes we need to store the data more than 255 characters. In such cases earlier I used to alter the table in the database. But now I found the better solution for this problem. Again a simple configuration in the domain class can do the trick for you. In static mapping of domain class you just need to assign the type to that particular field. If you want to store the huge data you can assign &#8220;text&#8221; to it<\/p>\n<pre lang=\"groovy\">\r\nclass Event {\r\n    String title;\r\n    Date date;\r\n  \r\n    static mapping = {\r\n        title type:\"text\"\r\n    }\r\n}\r\n<\/pre>\n<p>If this doesn&#8217;t look a right solution to you and you want specific length to the data as we can do in database you can do that here as well<\/p>\n<pre lang=\"groovy\">\r\n static mapping = {\r\n        title column: \"title\", sqlType: \"varchar(5000)\"\r\n    }\r\n<\/pre>\n<p>This is really so easy, its just I never looked for the right solution<br \/>\n<\/p>\n<p>Hope it helps<br \/>\n<a href=\"http:\/\/www.tothenew.com\/blog\/author\/uday\/\">Uday Pratap Singh<\/a><br \/>\n<a href=\"mailto:uday@intelligrape.com\">uday@intelligrape.com<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Grails automatically identifies what should be the datatype of the field in sql table e.g; fields with String datatype are converted to varchar(255), but sometimes we need to store the data more than 255 characters. In such cases earlier I used to alter the table in the database. But now I found the better [&hellip;]<\/p>\n","protected":false},"author":11,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":12},"categories":[7],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/834"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=834"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/834\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=834"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=834"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=834"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}