History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: GRAILS-1862
Type: Task Task
Status: Open Open
Priority: Major Major
Assignee: Graeme Rocher
Reporter: aambardekar
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Grails

Inheritance

Created: 20/Nov/07 01:05 PM   Updated: 21/Dec/07 12:03 PM
Component/s: Scaffolding
Affects Version/s: 0.6
Fix Version/s: None

Time Tracking:
Not Specified

Environment:
grails 0.6 windows


 Description  « Hide
We have domain classes with following relationship - inheritance
Product Has Many sprint and Projects
Sprint extends Project

class Product {
static hasMany = [features:ProductFeature, projects:Project, sprints:Sprint, issues:Issue, tasks:Task, attachments:Attachment, notes:Note, links:Hyperlink]
String productName
String productKey
...... other attribs
}

class Project {
static hasMany = [tasks:Task, issues:Issue, features:ProductFeature, teamMembers:User, attachments:Attachment, notes:Note, links:Hyperlink]
static belongsTo = [Product]
static optionals = ['productVersion']

Product product
...... other attribs
}
class Sprint extends Project {
//Inherited relationships:
// static hasMany = [tasks:Task, issues:Issue, teamMembers:User, attachments:Attachment, notes:Note, links:Hyperlink]
// static belongsTo = [Product]

Integer sprintNumber
}

When a new product is created using scaffold pages. It can be updated again using scaffold pages. Everything works as intended. Now when we setup sprint and project for a product, Now product can not be updated anymore because of following exception.
org.codehaus.groovy.runtime.InvokerInvocationException: org.hibernate.WrongClassException: Object with id: 1 was not of the specified subclass: Sprint (loaded object was of wrong class class Project)
at org.codehaus.groovy.runtime.metaclass.ReflectionMetaMethod.invoke(ReflectionMetaMethod.java:64)
at org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:678)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:689)
at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:894)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:531)
at groovy.lang.Closure.call(Closure.java:290)
at groovy.lang.Closure.call(Closure.java:285)
at org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsControllerHelper.handleAction(SimpleGrailsControllerHelper.java:526)
at org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsControllerHelper.executeAction(SimpleGrailsControllerHelper.java:385)
at org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsControllerHelper.handleURI(SimpleGrailsControllerHelper.java:240)
at org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsControllerHelper.handleURI(SimpleGrailsControllerHelper.java:152)
at org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsController.handleRequest(SimpleGrailsController.java:88)
at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:45)
at org.codehaus.groovy.grails.web.servlet.GrailsDispatcherServlet.doDispatch(GrailsDispatcherServlet.java:241)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:755)

Note sure weather there is something wrong this inheritance relationship. If I remove inheritance relationship between project and sprint, everything works as intended. Please advice.



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
aambardekar - 21/Dec/07 12:03 PM
I upgraded grails to 1.0. RC3
Sprint.findAllwhere(product:product) returns me all the Sprint associated with that product
Project.findAllWhere(product:product) returns 0 records.

I have noticed that with grails 1.0 RC3 two sets of columns are maintained for inheritance product_id for base class and sprint_product_id for derived class.

findAllWhere is looking for column sprint_product_id which is not populated when project is created and used only for Sprint.

I am not getting proper results using createCriteria as well.

Please help!!!!