Mark and src/groovy base domain class

18 views
Skip to first unread message

Bill James

unread,
Sep 5, 2014, 12:38:26 AM9/5/14
to groovy-grai...@googlegroups.com
Mark,

I remember you asking about using src/groovy classes as base classes for Domains, and I was sure we'd done that, so I tried it again.

Steps:
Create new grails project
Create class in src/groovy/dom called BaseDom.groovy like this:
package dom


class BaseDom {

   
String baseString
   
Long baseLong
}


Create a new Domain ChildDom.groovy in the domains directory like this (I added some mappings for fun:
package test.domain
import dom.BaseDom
class ChildDom extends BaseDom {
   
String childString
   
Long childLong
   
Double childDouble
   
static constraints = {
        baseString
( nullable: true )
        childLong
( nullable: false )
        childDouble
( nullable: true )
   
}
   
static mapping = {
        baseString
( column: 'bstr' )
   
}
}

You should be able to see what DDL will be generated by running schema-export:
grails dev schema-export generate .\ddl.sql

That should show you the DDL it would use to generate a single table for ChildDom containing the fields from BaseDom:

    drop table child_dom if exists;
    create table child_dom
(
        id bigint generated
by default as identity,
        version bigint
not null,
        base_long bigint
not null,
        bstr varchar
(255),
        child_double
double,
        child_long bigint
not null,
        child_string varchar
(255) not null,
        primary key
(id)
   
);

Is this what you were asking about?


Mark Fortner

unread,
Sep 5, 2014, 11:41:13 AM9/5/14
to groovy-grai...@googlegroups.com
Hi Bill,
That's what I was doing.  Except, when I started up, it threw an exception -- I don't remember which one.  I remember spending a day trying to track it down, and then just decided to brute force it, and create a POGO to domain object copying method.  When I get a chance I'll try and reproduce the error.

Mark
Reply all
Reply to author
Forward
0 new messages