Problem with Grails Domain Object

374 views
Skip to first unread message

Brady Hegberg

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

Message
Method on class [com.fl.dataalert.services.GwtMessage] 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?

Thanks,
Brady

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

unread,
May 15, 2015, 12:27:59 PM5/15/15
to groo...@googlegroups.com
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
colin.ha...@gmail.com

--
You received this message because you are subscribed to the "Groovy Users of Minnesota" group.
 
To post to this group, send email to groo...@googlegroups.com
To unsubscribe from this group, send email to groovymn-u...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/groovymn?hl=en
---
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 groovymn+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ted Naleid

unread,
May 15, 2015, 12:36:56 PM5/15/15
to groo...@googlegroups.com
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: http://grails.github.io/grails-doc/2.5.0/guide/testing.html#unitTestingDomains

Brady Hegberg

unread,
May 15, 2015, 1:56:21 PM5/15/15
to groo...@googlegroups.com
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.

Controller:

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

Service:

@Transactional
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.

-Brady

On Fri, May 15, 2015 at 11:27 AM, Colin Harrington <colin.ha...@gmail.com> wrote:

Brady Hegberg

unread,
May 15, 2015, 1:57:52 PM5/15/15
to groo...@googlegroups.com

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

-Brady
Reply all
Reply to author
Forward
0 new messages