Hi,
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!!