{"id":19044,"date":"2015-04-17T16:05:12","date_gmt":"2015-04-17T10:35:12","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=19044"},"modified":"2015-04-17T16:05:12","modified_gmt":"2015-04-17T10:35:12","slug":"making-a-domain-non-persistent","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/making-a-domain-non-persistent\/","title":{"rendered":"Making a domain non-persistent"},"content":{"rendered":"<p>In grails app, there might come scenarios where one need to create a non-persistent domain rather than creating a command obejct or POJO \/ POGO.<\/p>\n<p>GORM comes with a handy static property mapWith which has default value GORM (which associates any domain with gorm persistence layer).<br \/>\nTo make a domain non persistent set mapWith=&#8221;none&#8221;. For example, see Ticket domain below<\/p>\n<p>[code lang=&#8221;groovy&#8221;]<br \/>\npublic class Ticket {<br \/>\n    String id<br \/>\n    List&lt;Long&gt; productInstanceId<br \/>\n    static hasMany = [productInstanceId:Long]<br \/>\n    static mapWith = &quot;none&quot;<br \/>\n}<br \/>\n[\/code]<\/p>\n<p>Advantages:-<\/p>\n<ol>\n<li>Still behaves like a GORM Domain in most of the cases like Ticket domain above is still accessible by GrailsDomainClass<\/li>\n<li>When using multiple database , still respects the convention over configuration policy.<\/li>\n<li>supports scaffolding while same can&#8217;t be done for command objects. <\/li>\n<\/ol>\n<hr>\n<p>Also, at some point of time to check on a particular domain that what type of mapping it has, fetch the static property with domain class. For the domain above,  it would be <\/p>\n<p>[code lang=&#8221;groovy&#8221;]<br \/>\nTicket.mapWith<br \/>\n[\/code]<\/p>\n<p>or<\/p>\n<p>[code lang=&#8221;groovy&#8221;]<br \/>\nTicket.class.mapWith<br \/>\n[\/code]<\/p>\n<p>If doing a dynamic check then can find it with the help of DefaultGrailsDomainClass.<\/p>\n<p>[code lang=&#8221;groovy&#8221;]<br \/>\nGrailsDomainClass domainClass = new DefaultGrailsDomainClass(Ticket.class)<br \/>\ndomainClass.mappingStrategy<br \/>\n[\/code]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In grails app, there might come scenarios where one need to create a non-persistent domain rather than creating a command obejct or POJO \/ POGO. GORM comes with a handy static property mapWith which has default value GORM (which associates any domain with gorm persistence layer). To make a domain non persistent set mapWith=&#8221;none&#8221;. For [&hellip;]<\/p>\n","protected":false},"author":119,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":4},"categories":[7],"tags":[29,4840,1757,1758],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/19044"}],"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\/119"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=19044"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/19044\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=19044"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=19044"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=19044"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}