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 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 using the Resources plugin in Grails 2.0.1. The issue I'm having is getting
I'm having a problem right now, I have 2 domain classes namely Doctor and
I'm using Grails 2.0, and I'm having trouble getting the code to recognize an
Using Grails and CXF, I have published a small web service that looks like
I'm developing application using Grails framework and I'm having problems with hasErrors when invoked
I'm having a problem getting the select tag to work for me in Grails.
I'm pretty new on grails, I'm having a problem in matches validation using regex.
I'm using Grails and I have a local-plugin (that I wrote) that I'm using
I am using Grails 1.3.7, and have the following domain classes: package com.fxpal.test class
I am having problems when using dependency injection with Services in Grails. class ExampleService{

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.