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 3945308
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:00:08+00:00 2026-05-20T01:00:08+00:00

I am using Grails 1.3.6 and I am having problems getting saves to cascade

  • 0

I am using Grails 1.3.6 and I am having problems getting saves to cascade properly. The problem is specifically with classes that have two parent classes. A simplified version of what I am attempting is this:

class Location {
    String city
    static hasMany = [authors: Author, publishers: Publisher]
}

class Author {
    String name
    static belongsTo = [location: Location]
    static hasMany = [books: Book]
}

class Publisher {
    String name
    static belongsTo = [location: Location]
    static hasMany = [books: Book]
}

class Book {
    String title
    static belongsTo = [author: Author, publisher: Publisher]
}

class Srv1Service {

    static transactional = true

    def loadData() {
        def l1 = new Location(city: "London")

        def a1 = new Author(name: "Graham Greene")
        l1.addToAuthors(a1)

        def p1 = new Publisher(name: "Some Press")
        l1.addToPublishers(p1)

        def b1 = new Book(title: "The Comedians")
        a1.addToBooks(b1)
        p1.addToBooks(b1)

        l1.save()
    } 
}

If I run the above loadData, the Book instance is saved before the Publisher instance, resulting in the error “not-null property references a null or transient value: adhoc.Book.publisher”.

I have tried various different ways of defining the relationships with little success. I have tried interim saves, and this does work, but I can see that parent tables are updated as I save the child data – ie Location, Author and Publisher all get updated to version 1. (And also I would like to keep the code as simple as I can.) I would like to avoid linking tables.

Any advice is gratefully received!

  • 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-20T01:00:09+00:00Added an answer on May 20, 2026 at 1:00 am

    Okay, so the key here is that saves are cascaded from parent to children. You have a problem when it comes to Book because Book is the child to both Publisher and Author. GORM tries to save Location, Location tries to save Author, Author tries to save Book BUT the save fails because Book has a transient Publisher.

    Try adding an intermediate save right before you create your Book:

    def loadData() {
        def l1 = new Location(city: "London")
    
        def a1 = new Author(name: "Graham Greene")
        l1.addToAuthors(a1)
    
        def p1 = new Publisher(name: "Some Press")
        l1.addToPublishers(p1)
        l1.save() // add this save
    
        def b1 = new Book(title: "The Comedians")
        a1.addToBooks(b1)
        p1.addToBooks(b1)
    
        l1.save()
    } 
    

    I created a local Grails project with your domain classes adding in this save. The cascading is working as you would expect.

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

Sidebar

Related Questions

I'm just getting started with grails, and I'm having an issue. I have a
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
using Grails 1.1.1 I have domain in Grails Person. Person can be related to
We're using Grails but with an existing model layer and DAO layer. We have
I have an application that I am working on modifying and I am having
I'm using Grails Mail plugin and trying to send email and keep getting: Error
I have been using Grails for last 3 weeks (learning and working). I have
I have been working on the project where application is using grails 1.2.2.... Now
Im am having problems with the remember me functionality of the grails acegi plugin
I have noticed that after my Grails app has been deployed for about 2

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.