Problem with Grails Domain Object

Skip to first unread message

Brady Hegberg

May 15, 2015, 12:14:00 PM5/15/15
I created a domain object in a project that already had a number of domain objects (created by someone else months ago) object is in the same package as the others but when I call it I get:

Method on class [] was used outside of a Grails application. If running in the context of a test using the mocking API or bootstrap Grails correctly.

I've tried a number of things to get it working but to no avail.  Has anyone seen this?  Any ideas to try?


My class...though I can't even tell if the problem is here...

class GwtMessage {

int gwtAccountConfigId
int gwtAccountSiteId
String messageSubject
Date messageDate
boolean isMessageRead
Date insertDate
static mapping = {
datasource 'dataSource_datawarehouse'
//table mappings
table name:'GWT_MESSAGE', schema:"SITE_CONTENT"
id column:'GWT_MESSAGE_ID', generator:'sequence', params:[sequence:'SITE_CONTENT.SEQ_GWT_MESSAGE']
gwtAccountConfigId column: 'GWT_ACCOUNT_CONFIG_ID'
gwtAccountSiteId column: 'GWT_ACCOUNT_SITE_ID'
messageSubject column: 'MESSAGE_SUBJECT', sqlType: 'varchar2(1024 byte)'
messageDate column: 'MESSAGE_DT'
isMessageRead column: 'IS_MESSAGE_READ_FLG', type: 'yes_no'
insertDate column: 'INSERT_DT'
version false
    static constraints = {

Colin Harrington

May 15, 2015, 12:27:59 PM5/15/15
Hi Brady, 

Can you share how you are using the Domain class?

I've seen this type of error if I try to use the domain class statically, in scripts or before the whole application has time to load the domain class plugin.

Also, what version of Grails?

Colin Harrington

You received this message because you are subscribed to the "Groovy Users of Minnesota" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at
You received this message because you are subscribed to the Google Groups "Groovy Users of Minnesota" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
For more options, visit

Ted Naleid

May 15, 2015, 12:36:56 PM5/15/15
I'm a little unclear if this is failing in a test or only working in a test.

I believe that I've seen this error before in unit tests when I forget to add my domain class to a @Mock annotation. 

See the unit test docs for specific examples of how to @Mock:

Brady Hegberg

May 15, 2015, 1:56:21 PM5/15/15
Sorry...some context:

I have a controller that fires when a service is hit.  I'm creating a WAR from this project and deploying it to Tomcat 6.0.37.


class GwtMessageController {
  static allowedMethods = [index: 'GET', show: 'GET']
    def gwtMessageService
    def index() {
  def gwtMessages = gwtMessageService.findUnhandledGwtMessages()
        render gwtMessages


class GwtMessageService {
    def grailsApplication
    def dataSourceUtilService
    def findUnhandledGwtMessages() {
def results = GwtMessage.getAll()

I also tried GwtMessage.list()

Grails is version 2.4.4

The app is starting and creating a database pool.  The other Services call domain objects the same way (AFAIK) and they return results.  I'm hitting the service well after the app finishes loading.


On Fri, May 15, 2015 at 11:27 AM, Colin Harrington <> wrote:

Brady Hegberg

May 15, 2015, 1:57:52 PM5/15/15

Haven't tried it from a test yet.  Maybe I'll give that a try.  (I should be doing it already TDD-wise :-/ )

Reply all
Reply to author
0 new messages