Does domain object has to map a table?

31 views
Skip to first unread message

GrailsNewbie

unread,
Sep 29, 2016, 6:16:57 PM9/29/16
to Grails Dev Discuss
Hello,

If my grails service class returns a result set of type cursor (multiple rows) can I map them to domain? in other words can I use domain as model to map a row set . For example if I have a Person table with columns Id, First Name, Last Name, Address etc. and my result set returns me rows with only columns FirstName and LastName . Can I create a domain called Person and not map it directly to table Person instead use it a plain model?

Thanks.

Jeff Brown

unread,
Sep 30, 2016, 4:49:46 PM9/30/16
to grails-de...@googlegroups.com
On September 29, 2016 at 5:17:11 PM, GrailsNewbie
You can’t create a domain lass and not map it to a table.  Part of the
definition of a domain class is that it is mapped to a table (assuming
you are using Hibernate GORM).

You could create a class that isn’t a domain class and use that for
what you are describing.  You should define that class under
src/groovy/ for Grails 2 or src/main/groovy for Grails 3.




JSB
--
Jeff Scott Brown
OCI Grails Practice Lead
Principal Software Engineer

Autism Strikes 1 in 166
Find The Cause ~ Find The Cure
http://www.autismspeaks.org/

Jeff Brown

unread,
Sep 30, 2016, 4:50:50 PM9/30/16
to grails-de...@googlegroups.com


On September 30, 2016 at 3:49:43 PM, Jeff Brown (bro...@ociweb.com) wrote:
>
>
> On September 29, 2016 at 5:17:11 PM, GrailsNewbie (prasha...@gmail.com) wrote:
> > Hello,
> >
> > If my grails service class returns a result set of type cursor (multiple
> > rows) can I map them to domain? in other words can I use domain as model to
> > map a row set . For example if I have a Person table with columns Id, First
> > Name, Last Name, Address etc. and my result set returns me rows with only
> > columns FirstName and LastName . Can I create a domain called Person and
> > not map it directly to table Person instead use it a plain model?
> >
>
> You can’t create a domain lass and not map it to a table. Part of the definition of a domain
> class is that it is mapped to a table (assuming you are using Hibernate GORM).
>
> You could create a class that isn’t a domain class and use that for what you are describing.
> You should define that class under src/groovy/ for Grails 2 or src/main/groovy for Grails
> 3.
>


Strictly speaking that isn’t really true.  You could use…

   static mapWith = “none"

But it isn’t clear why you want the thing to be a domain class to begin with.
Reply all
Reply to author
Forward
0 new messages