Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8234137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:22:37+00:00 2026-06-07T18:22:37+00:00

I have three domain objects defined as : class Member { String name static

  • 0

I have three domain objects defined as :

class Member {
    String name

    static constraints = {}
    static belongsTo=[community:Community]
}

class Community {
    String leaderName
    String code

    static constraints = {}
    static hasMany=[members: Member]
    static belongsTo=[bank:Bank]
}

class Bank {

    String bankName
    static hasMany=[communities: Community]
    static constraints = {}
}

When I tried to initialize these domain objects with some test data in BootStrap.groovy config class as :

 def init = { servletContext ->

            def m1 = new Member(name:"M1_Name")
            def m2 = new Member(name:"M2_Name")
            def m3 = new Member(name:"M3_Name")

            m1.save(failOnError:true)
            m2.save(failOnError:true)
            m3.save(failOnError:true)

            def comA = new Community(leaderName:"LeaderA", code:"AA")
            def comB = new Community(leaderName:"LeaderB", code:"BB")

            comA.addToMembers(m1)
            comA.addToMembers(m2)
            comB.addToMembers(m3)

            comA.save(failOnError:true)
            comB.save(failOnError:true)

            def bankA = new Bank(bankName:"BankA")
            def bankB = new Bank(bankName:"BankB")

            bankA.addToCommunities(comA)
            bankB.addToCommunities(comB)

            bankA.save(failOnError:true)
            bankB.save(failOnError:true)
        }

I am getting following error :

| Loading Grails 2.0.4
| Configuring classpath.
| Environment set to development.....
| Packaging Grails application.....
| Compiling 3 source files.....
| Running Grails application
| Error 2012-07-13 22:14:44,798 [pool-5-thread-1] ERROR context.GrailsContextLoader  - Error executing bootstraps: Validation Error(s) occurred during save():
- Field error in object 'mygrailtests.Member' on field 'community': rejected value [null]; codes [mygrailtests.Member.community.nullable.error.mygrailtests.Member.community,mygrailtests.Member.community.nullable.error.community,mygrailtests.Member.community.nullable.error.mygrailtests.Community,mygrailtests.Member.community.nullable.error,member.community.nullable.error.mygrailtests.Member.community,member.community.nullable.error.community,member.community.nullable.error.mygrailtests.Community,member.community.nullable.error,mygrailtests.Member.community.nullable.mygrailtests.Member.community,mygrailtests.Member.community.nullable.community,mygrailtests.Member.community.nullable.mygrailtests.Community,mygrailtests.Member.community.nullable,member.community.nullable.mygrailtests.Member.community,member.community.nullable.community,member.community.nullable.mygrailtests.Community,member.community.nullable,nullable.mygrailtests.Member.community,nullable.community,nullable.mygrailtests.Community,nullable]; arguments [community,class mygrailtests.Member]; default message [Property [{0}] of class [{1}] cannot be null]

Message: Validation Error(s) occurred during save():
- Field error in object 'mygrailtests.Member' on field 'community': rejected value [null]; codes [mygrailtests.Member.community.nullable.error.mygrailtests.Member.community,mygrailtests.Member.community.nullable.error.community,mygrailtests.Member.community.nullable.error.mygrailtests.Community,mygrailtests.Member.community.nullable.error,member.community.nullable.error.mygrailtests.Member.community,member.community.nullable.error.community,member.community.nullable.error.mygrailtests.Community,member.community.nullable.error,mygrailtests.Member.community.nullable.mygrailtests.Member.community,mygrailtests.Member.community.nullable.community,mygrailtests.Member.community.nullable.mygrailtests.Community,mygrailtests.Member.community.nullable,member.community.nullable.mygrailtests.Member.community,member.community.nullable.community,member.community.nullable.mygrailtests.Community,member.community.nullable,nullable.mygrailtests.Member.community,nullable.community,nullable.mygrailtests.Community,nullable]; arguments [community,class mygrailtests.Member]; default message [Property [{0}] of class [{1}] cannot be null]

   Line | Method
->>  13 | doCall                           in BootStrap$_closure1
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   301 | evaluateEnvironmentSpecificBlock in grails.util.Environment
|   294 | executeForEnvironment . . . . .  in     ''
|   270 | executeForCurrentEnvironment     in     ''
|   303 | innerRun . . . . . . . . . . . . in java.util.concurrent.FutureTask$Sync
|   138 | run                              in java.util.concurrent.FutureTask
|   886 | runTask . . . . . . . . . . . .  in java.util.concurrent.ThreadPoolExecutor$Worker
|   908 | run                              in     ''
^   662 | run . . . . . . . . . . . . . .  in java.lang.Thread

Here, line 13 is

m1.save(failOnError:true)

Could you please suggest me what’s wrong going on? Or what I am missing.

UPDATE :
It is working without errors when I remove belongsTo relation in Member and Community objects.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T18:22:38+00:00Added an answer on June 7, 2026 at 6:22 pm

    When you add the belongsTo: Community part to Member you are saying that Member will belong to a Community.

    When you construct the Member object, you are not providing the Community that is connected with the Member. Committing the Member like this is blowing up because you haven’t yet said the Community it belongs to.

    You don’t need those save calls there anyway, as belongsTo marks that Community will be responsible for the save. Take out the 3 m[x].save() lines, readd the belongsTo code and see if it works as expected.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three domain class class Stock { Product product } and class Product
Introduction Let's say I have three Domain Objects: Proposition Phase Task A Proposition can
I have a domain service specifically built for LightSwitch where I defined three entities.
In my application I have Users, Organisations and Employees. There are domain objects for
I have a website with three domains .com, .de and .it Each domain needs
I have there domain classes: Person. (Person.ID, Name,Address) Designation.(Designation.ID, Title, Band) SalarySlip (Person.ID, Designation.ID,
I have a domain name and my rails application. Is there any way to
If I have a List in a Grails domain class, is there a way
I have an entity defined as follows (code generated by the VS2010 POCO generator):
I have created domain model and define entities, value objects, Services and so on.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.