Grails

GORM Inheritance bug: a subcass of a tree (one-to-many with self) doesn't inherit the parent/children relationship

Details

  • Type: Sub-task Sub-task
  • Status: Closed Closed
  • Priority: Critical Critical
  • Resolution: Fixed
  • Affects Version/s: 1.1-beta2
  • Fix Version/s: 1.2.2, 1.3-M1
  • Component/s: None
  • Labels:
    None
  • Patch Submitted:
    Yes

Description

given the same basic Domain I was using in the attached example
http://jira.codehaus.org/browse/GRAILS-3209
subclassing a tree doesn't inherit

for

class Party{}

class Organization extends Party {
   static hasMany = [children: Organization]
   Organization parent
}

class ExtOrganization extends Organization{}

For this the parent/children relationship won't work for ExtOrganization, even when viewed as Organization.
The relationship/mappings/ownership should just be inherited, but they are not.

First, this will thrown an error saying the there needs to be owner defined between ExtOrganization and Organization.
So you can add

belongsTo = Organization

to get past that.

But the parent/children mapping is broken and the children collection returns nothing for instances of ExtOrganization despite having parents set. This is true if viewed as Organization or ExtOrganization. Although instances of Organization work.

attach example
click on Load Test Data
view Organization or ExtOrganization list
view instances of ExtOrganization (name Ext*)

Activity

Hide
Steve Tekell added a comment -

oops, forgot to set
component = Persistance
effected versions = 1.0.3

Show
Steve Tekell added a comment - oops, forgot to set component = Persistance effected versions = 1.0.3
Hide
Steve Tekell added a comment -

FYI if you take Party out so Organization doesn't extend anything, you will still need the belongsTo, but ExtOrganization's children will be there.
So the extra level of inheritance is significant.

Show
Steve Tekell added a comment - FYI if you take Party out so Organization doesn't extend anything, you will still need the belongsTo, but ExtOrganization's children will be there. So the extra level of inheritance is significant.
Hide
Marc Palmer added a comment -

I say this is critical. Its really daft that this is not inherited.

Show
Marc Palmer added a comment - I say this is critical. Its really daft that this is not inherited.
Hide
Graeme Rocher added a comment -

Seems to be a problem with the discriminator column in table-per-heirarchy mapping. If you change your code to:

class Party{
   static mapping = {
        tablePerSubclass true // THE ADDITION IS HERE
    }
}

class Organization extends Party {
   static hasMany = [children: Organization]
   Organization parent
}

class ExtOrganization extends Organization{}

It works. Investigating why it is a problem with table-per-heirarchy

Show
Graeme Rocher added a comment - Seems to be a problem with the discriminator column in table-per-heirarchy mapping. If you change your code to:
class Party{
   static mapping = {
        tablePerSubclass true // THE ADDITION IS HERE
    }
}

class Organization extends Party {
   static hasMany = [children: Organization]
   Organization parent
}

class ExtOrganization extends Organization{}
It works. Investigating why it is a problem with table-per-heirarchy
Hide
Graeme Rocher added a comment -

Bug was caused by a workaround we had for this issue: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2855

I removed the workaround since it was resolved in Hibernate core and the problem went away.

Show
Graeme Rocher added a comment - Bug was caused by a workaround we had for this issue: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2855 I removed the workaround since it was resolved in Hibernate core and the problem went away.
Hide
Graeme Rocher added a comment -

Unfortunately by removing the workaround for the above Hibernate issue it caused regressions elsewhere. It seems that the issue is in fact not fixed and should be re-opened in Hibernate's JIRA

The current workaround from a Grails perspsective is to use table-per-subclass instead, which behaves as expected

Show
Graeme Rocher added a comment - Unfortunately by removing the workaround for the above Hibernate issue it caused regressions elsewhere. It seems that the issue is in fact not fixed and should be re-opened in Hibernate's JIRA The current workaround from a Grails perspsective is to use table-per-subclass instead, which behaves as expected
Hide
Graeme Rocher added a comment -

There is no scope / time to resolve these remaining lower priority issues for 1.2 so moving to 1.3

for 1.2 final only issues considered blocking will now be fixed

Show
Graeme Rocher added a comment - There is no scope / time to resolve these remaining lower priority issues for 1.2 so moving to 1.3 for 1.2 final only issues considered blocking will now be fixed
Hide
Graeme Rocher added a comment -

Fixed by changes in GRAILS-5904

Thanks for the patch

Show
Graeme Rocher added a comment - Fixed by changes in GRAILS-5904 Thanks for the patch

People

Vote (4)
Watch (5)

Dates

  • Created:
    Updated:
    Resolved: