grails-data-mapping icon indicating copy to clipboard operation
grails-data-mapping copied to clipboard

GRAILS-5208: Discriminator used in table-per-subclass not implemented

Open graemerocher opened this issue 16 years ago • 4 comments

Original Reporter: frankly.watson Environment: Linux Version: 1.2-M3 Migrated From: http://jira.grails.org/browse/GRAILS-5208

I have spent quite a time trying to get a discriminator applied to a table-per-subclass hierarchy using GORM domain objects, but nothing appears to work.

Judging by Hibernate docs (http://docs.jboss.org/hibernate/core/3.3/reference/en/html/inheritance.html#inheritance-tablepersubclass-discriminator) this should be possible

My example classes, and in comments my various attempts (the documentation on how to achieve this does not appear up to date either - http://jira.codehaus.org/browse/GRAILS-5168)

package foo

class Parent {

String name
int counter

static mapping = {
    tablePerHierarchy false // also tried to replace with 'tablePerSubclass true'

    //(1) discriminator column: [name: "product_type", sqlType: "varchar"], value: "parent"
    //(2) discriminator column: "product_type", value: "parent"
    //(3) discriminator value: "parent"
    discriminator "parent"
}

static constraints = {
}

}

and

package foo

class Child extends Parent {

String color

static mapping = {
    discriminator "child"
}

}

Some degree of discriminator is supported by commenting out

 tablePerHierarchy false

In this instance I seed a single PARENT table and a column called CLASS, the default discriminator

However in table-per-subclass i never see either a CLASS column, or otherwise any custom column name I have specified.

The following Bug (FIXED in 1.1RC1) suggests that I should be able to specify a user-defined discriminator value - http://jira.codehaus.org/browse/GRAILS-3913 - although it makes no comment on whether this is only applicable to tablePerHieararchy. I do see my custom discriminator column name appear in table-per-hierarchy, not in TPS-Class tho.

The following also suggests there is something working, although not completely... http://jira.codehaus.org/browse/GRAILS-4487

I am suposing that logic i have so far uncovered which does work is the conclusion of this discussion - http://www.nabble.com/Hierarchy---Discriminator-td19615294.html

Based on the above, and others observing the same since May 09, http://www.pubbs.net/grails/200905/68819/, leads me to conclude that support is only partially there; it is for tablePerHierarchy but not at all for tablePerSubclass

graemerocher avatar Oct 08 '09 08:10 graemerocher

shilad said: This seems to still be an issue in 1.3.3.

graemerocher avatar Aug 16 '10 21:08 graemerocher

graemerocher said: I'm not sure what the issue is and why you would want to use a discriminator in table-per-subclass. Hibernate doesn't need a discriminator for table-per-subclass so why use one? More detail would be good..

graemerocher avatar Aug 17 '10 04:08 graemerocher

schmolly159 said: Another example where a discriminator would be required is if you have subclasses of a subclass. In this case run-app is dying with a Hibernate exception stating that a discriminator is not found because it was never set up for table-per-subclass in Grails.

graemerocher avatar Apr 20 '11 14:04 graemerocher

graemerocher said: This issue covers discriminator definitions in table-per-subclass mapping which is a new feature to be implemented not a bug. If you have found a regression which is causing this exception to be raised in normal table-per-hierarchy mappings then you should raise a separate JIRA for that issue and attach an example.

graemerocher avatar Oct 26 '11 13:10 graemerocher