Details
-
Type:
Sub-task
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 1.0.1
-
Fix Version/s: 1.1-beta3
-
Component/s: Persistence
-
Labels:None
-
Testcase included:yes
Description
As discussed on users mailing list http://www.nabble.com/Multiple-one-to-many-relationships-tt16110042.html
Example project attached to this bug report.
Create the following two classes:
class Group {
// Every user has a bunch of groups that it owns
static belongsTo = [ owner : User ]
// In addition, every group has members that are users
static hasMany = [ members : User ]
}
class User {
// Every user has a bunch of groups that it owns
static hasMany = [ groups: Group ]
static mappedBy = [ groups:"owner" ]
}
Every group is owned by a user (bidirectional one-to-many), and it also contains a list of members (unidirectional one-to-many). When executing grails test-app, we get the following error:
Running script /opt/local/grails-1.0.1/scripts/TestApp.groovy [0] spring.GrailsWebApplicationContext Refreshing org.codehaus.groovy.grails.commons.spring.GrailsWebApplicationContext@299c3e: display name [org.codehaus.groovy.grails.commons.spring.GrailsWebApplicationContext@299c3e]; startup date [Wed Mar 19 11:27:26 PDT 2008]; root of context hierarchy [0] spring.GrailsWebApplicationContext Bean factory for application context [org.codehaus.groovy.grails.commons.spring.GrailsWebApplicationContext@299c3e]: org.springframework.beans.factory.support.DefaultListableBeanFactory@4eba57 org.codehaus.groovy.grails.exceptions.GrailsDomainException: No owner defined between domain classes [class User] and [class Group] in a many-to-many relationship. Example: def belongsTo = Group at Package_groovy$_run_closure5_closure22.doCall(Package_groovy:231) at Package_groovy$_run_closure5_closure22.doCall(Package_groovy) at Init_groovy$_run_closure6.doCall(Init_groovy:127) at Package_groovy$_run_closure5.doCall(Package_groovy:221) at Package_groovy$_run_closure5.doCall(Package_groovy) at Bootstrap_groovy$_run_closure2.doCall(Bootstrap_groovy:56) at Bootstrap_groovy$_run_closure2.doCall(Bootstrap_groovy) at TestApp_groovy$_run_closure9.doCall(TestApp_groovy:259) at TestApp_groovy$_run_closure9.doCall(TestApp_groovy) at TestApp_groovy$_run_closure3.doCall(TestApp_groovy:115) at TestApp_groovy$_run_closure3.doCall(TestApp_groovy) at TestApp_groovy$_run_closure1.doCall(TestApp_groovy:63) at TestApp_groovy$_run_closure1.doCall(TestApp_groovy) at gant.Gant.dispatch(Gant.groovy:271) at gant.Gant.this$2$dispatch(Gant.groovy) at gant.Gant.invokeMethod(Gant.groovy) at gant.Gant.processTargets(Gant.groovy:436) at gant.Gant.processArgs(Gant.groovy:372) at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:101) at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:130) Error loading plugin manager: No owner defined between domain classes [class User] and [class Group] in a many-to-many relationship. Example: def belongsTo = Group
Note that by changing the bidirectional relationship to be unidirectional (by setting "static belongsTo = User" in the Group class) the error goes away, but we lose the ability to access the Group's owner.
Activity
- All
- Comments
- Work Log
- History
- Activity
- Git Commits
Bulk closing bunch of resolved issues