GRAILS-5208: Discriminator used in table-per-subclass not implemented
- Dominant language
- Groovy
- Stars
- 2.9k
- Forks
- 975
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 92
Description
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
Contributor guide
Assessment
This issue has not been assessed yet.