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

  • Home
  • SEARCH
  • 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 6576907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:34:11+00:00 2026-05-25T15:34:11+00:00

I am having a problem saving a Domain object. Below is my Controller code:

  • 0

I am having a problem saving a Domain object. Below is my Controller code:

def onContactRequest = {

    if(request.method == 'POST') {
        if(User.findByUserTelephone(params.userTelephone)) {
            User thisUser = User.findByUserTelephone(params.userTelephone)
            Contact thisContact = new Contact()

            thisContact.setContact(thisUser)

            println("This Contact: " + thisContact.getContact());

            thisContact.setBelongsTo(request.user)

            println("This User: " + request.user)

            if(thisContact.save(flush: true)) {
                render(thisContact.belongsTo.userName + " just requested " + thisContact.getContact().userName )
            } else {
                render("There was a problem saving the Contact.")
                if( !thisContact.save() ) {
                   thisContact.errors.each {
                        println it
                   }
                }
            }
        } else {
            User thisUser = new User()
            thisUser.setUserName("Not Set")
            thisUser.setUserTelephone(params.userTelephone)
            thisUser.save()
            Contact thisContact = new Contact()
            thisContact.setContact(thisUser)
            thisContact.setBelongsTo(request.user)
            if(thisContact.save(flush: true)) {
                render(thisContact.belongsTo.userName + " just requested " + thisContact.getContact().userName )
            } else {
                render("There was a problem saving the Contact.")
                if( !thisContact.save() ) {
                   thisContact.errors.each {
                        println it + "\n"
                   }
                }
            }

        }
    } else {

    }

The error message is printed with the following code; hence it’s very ugly:

if( !thisContact.save() ) {
    thisContact.errors.each {
        println it + "\n"
    }
}

From what I can tell, it’s complaining that either the Contact or User instance is null; however that can’t be true (look below)

This Contact: org.icc.callrz.User.User : 2
This User: org.icc.callrz.User.User : 1

Field ‘user’ in org.icc.callrz.Contact.Contact is:

static belongsTo = [
    user:                                   User
]

Error detail below:

org.springframework.validation.BeanPropertyBindingResult: 1 errors
Field error in object 'org.icc.callrz.Contact.Contact' on field 'user': rejected value [null]; codes [org.icc.callrz.Contact.Contact.user.nullable.error.org.icc.callrz.Contact.Contact.user,org.icc.callrz.Contact.Contact.user.nullable.error.user,org.icc.callrz.Contact.Contact.user.nullable.error.org.icc.callrz.User.User,org.icc.callrz.Contact.Contact.user.nullable.error,contact.user.nullable.error.org.icc.callrz.Contact.Contact.user,contact.user.nullable.error.user,contact.user.nullable.error.org.icc.callrz.User.User,contact.user.nullable.error,org.icc.callrz.Contact.Contact.user.nullable.org.icc.callrz.Contact.Contact.user,org.icc.callrz.Contact.Contact.user.nullable.user,org.icc.callrz.Contact.Contact.user.nullable.org.icc.callrz.User.User,org.icc.callrz.Contact.Contact.user.nullable,contact.user.nullable.org.icc.callrz.Contact.Contact.user,contact.user.nullable.user,contact.user.nullable.org.icc.callrz.User.User,contact.user.nullable,nullable.org.icc.callrz.Contact.Contact.user,nullable.user,nullable.org.icc.callrz.User.User,nullable]; arguments [user,class org.icc.callrz.Contact.Contact]; default message [Property [{0}] of class [{1}] cannot be null]

Edit: I have no problem creating Contact domain objects using the ‘generate-all’ code.

SOLUTION: I had a look at the code in the view, and it looked like to create the ID was used, so I changed the code to:

thisContact.user.id = request.user.id

However, then I got an error: java.lang.NullPointerException: Cannot set property 'id' on null object but the output of println request.user was not blank so I wasn’t sure why that was appearing.

I then changed the offending line to:

thisContact.user = request.user

Now everything is working. 🙂

  • 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-05-25T15:34:11+00:00Added an answer on May 25, 2026 at 3:34 pm

    Try replacing:

    thisContact.setBelongsTo(request.user)
    

    With:

    thisContact.user = thisUser
    

    The syntax you are using is wrong as far as I know, not to mention that you construct thisUser and then go on to use request.user instead.

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

Sidebar

Related Questions

Having a problem getting a TreeView control to display node images. The code below
am having problem in Saving some data in my Java code. I have like
I'm having a problem with my Seam code and I can't seem to figure
I'm having a hard time figuring this validation problem. I have one parent domain
I am having problem with saving the changes to database. I am updating the
I'm having some trouble with my EF Code First model when saving a relation
I'm currently working with some code involving saving a file to a user-defined file.
I'm having a problem saving the result of a RPC. Basically the call is
I have having a problem saving the sign up form using Devise. I am
Okay, I'm having a problem saving after I've deleted all the objects I have

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.