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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:34:37+00:00 2026-05-15T19:34:37+00:00

I am stuck at this problem. The code looks ok to me(obviously I am

  • 0

I am stuck at this problem. The code looks ok to me(obviously I am missing something. The question is what it is?)

I have a Project class

def class project{
    ...
    Manager manager
 }

This is Person and Manager class definition

def class Person{
   String firstName
   String lastName
}

def class Manager extends Person{
   static hasMany = [ projects: Project]

}

The relationship is simple – A Project has one manager and a manager has many projects. As far as I know, in the one-to-many relationship the save cascades because it is bi-directional one-to-many. But when I do this

Project project = new Project()
Manager mgr = new Manager(...)
project.manager = mgr
project.save()

I get the following error
Caused by: org.hibernate.TransientObjectException: object references an unsaved transient instance – save the transient instance before flushing: Manager

and when I do this

Project project = new Project()
Manager mgr = new Manager(...)
project.manager = mgr
project?.manager.save()
project.save()

It works just fine. But I think project?.manger.save() shouldn’t be required!!

  • 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-15T19:34:38+00:00Added an answer on May 15, 2026 at 7:34 pm

    A quick fix would be to save the manager before saving the project.

    You also don’t have a belongsTo setup. Check out chapter 5 of the grails documentation.

    http://grails.org/doc/latest/

    “In the case of a bidirectional one-to-many where the many side does not define a belongsTo then the cascade strategy is set to “SAVE-UPDATE” for the one side and “NONE” for the many side.”

    So, if i get this correctly, you can call save on the mgr (the one side) but not save on the project side (to get cascading to work)

    In the case of a bidirectional one-to-many where the many side defines a belongsTo then the cascade strategy is set to “ALL” for the one side and “NONE” for the many side.

    You will also want to check out section 5.5.2.9, where you can specify custom cascading behavior.

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

Sidebar

Related Questions

Greetings, this is my very first question and I just do programming as a
My problem is hydrating a Viewmodel from a Linq2Sql object that has been returned
My iPad app hangs on startup sometimes. It looks like the main thread is
This is fairly difficult to explain. I am working on a text adventure at
I'm trying to learn Python, (i have 2.5.4) by writing a snake game, but
I just watched the following video: Introduction to Node.js and still don't understand how
Or any viable workaround. So, imagine a Master page that implements IFooMaster with a
I've tried looking at a bunch of forums, and despite a lot of tweaking
Here's the stack: Sproutcore 1.0.1046. Ruby 1.9.1, in RVM. Thin 1.2.7. Thor 0.13.8. Rack
The navigation commences with [[TTNavigator navigator] openURLAction:theUrl]; from one UIviewController controller and another UIViewController

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.