• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • Al Hobbs
  • salvin francis

Grails in action: MissingMethodException when creating one to one Integration test

Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know how many times this question has been asked but no one seems to answer satisfactorily.
I am following the Grails in Action book.

I have tried everything but cannot get this working. Seems like every new user is struggling with this issue. Grails team should post a list of common issue and solutions.

I am creating a business domain class and an address domain. Every business has one address and I am trying to create a integration test and however it does not work.

I created Integration test but when I run it I get this exception. Here is the code

class Business {

static hasOne = [address:Address];

String name;
String description;
Business business;

static constraints = {

static mapping = { address lazy:false }

class Address {
Business business;

String addressLine1;
String addressLine2;
String city;
String state;
String zipCode;
String email;
String phone;
String homePage;

static constraints = {
// zipCode(size:1..5,nullable:false);


Integration Test:

void saveCascadeAddess() {
def address = new Address(addressLine1: 'Line1', addressLine2: 'line 2',city:'city1');
def business = new Business(name:'b_name1', description:'desc1');
assertNotNull business.save();

def checkBusiness = Business.get(business.id);
assertEquals 'b_name1', checkBusiness.name;

def checkAddress = checkBusiness.address;
assertEquals 'Line1', checkAddress.addressLine1;

Result - The test fails.

I have tried running this code in grails console as well but I get the MethodMissingException.
Ranch Hand
Posts: 15304
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should read the docs on the hasOne. There is no addTo method created for a hasOne. That's why you're getting that exception.
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic