homicki opened a new issue, #16465:
URL: https://github.com/apache/grails-core/issues/16465

   ### Expected Behavior
   
   A table-per-hierarchy tree with no discriminator mapping uses the 
grails-data-hibernate5 default. That default is a column named class that 
stores the fully qualified class name of each row. An application that upgrades 
from grails-data-hibernate5 then reads its existing rows with no mapping change.
   
   The same tests pass on grails-data-hibernate5.
   
   If the new default is intended, a single configuration setting restores the 
grails-data-hibernate5 default, and the upgrade guide describes the change.
   
   ### Actual Behaviour
   
   With no discriminator mapping, grails-data-hibernate7 uses a column named 
DTYPE. That column stores the fully qualified name of the root class and the 
simple name of each subclass. For example, the stored values are 
example.Vehicle, Car and SportsCar.
   
   - With dbCreate: 'validate' and an existing table that has a class column, 
startup fails with SchemaManagementException: Schema validation: missing column 
[DTYPE] in table [vehicle].
   - A mapping of only discriminator column: 'class', with no value, fails at 
startup with MappingException: Could not parse discriminator value 'null' as 
discriminator type 'string'.
   
   ### Steps To Reproduce
   
   1. Define a table-per-hierarchy tree with no discriminator mapping:
   ```
   class Vehicle { String name }
   class Car extends Vehicle {}
   ```
   2. Create the vehicle table with a class discriminator column, as 
grails-data-hibernate5 creates it.
   3. Start the application with dbCreate: 'validate'. Startup fails with 
missing column [DTYPE].
   4. Map the discriminator column only, and start the application again. 
Startup fails with Could not parse discriminator value 'null':
   ```
   class Vehicle {
       String name
       static mapping = { discriminator column: 'class' }
   }
   ```
   
   *Cause*: GrailsDomainBinder.JPA_DEFAULT_DISCRIMINATOR_TYPE ([v8.0.0-RC1, 
line 
69](https://github.com/apache/grails-core/blob/v8.0.0-RC1/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/binder/GrailsDomainBinder.java#L69))
 is "DTYPE", and DefaultDiscriminatorBinder.bindDefaultDiscriminator uses that 
value as the column name of the root class. The grails-data-hibernate5 
GrailsDomainBinder uses RootClass.DEFAULT_DISCRIMINATOR_COLUMN_NAME, which is 
"class", and the fully qualified name of each class as its value.
   
   *Workaround*: map discriminator column: 'class', value: '<fully qualified 
name>' on each root class and discriminator '<fully qualified name>' on each 
subclass.
   
   It looks like pull request #16350 removes Hibernate 5 support on the 9.0.x 
branch. Once accepted, every application that has table-per-hierarchy classes 
and existing data must handle this new default.
   
   ### Environment Information
   
   - Grails 8.0.0-RC1
   - Hibernate  7.4.10.Final
   -  Groovy 5.1.3
   - JDK 25
   -  H2 2.4.240
   
   The code that causes the problem is the same in the v8.0.0-RC2 tag.
   
   ### Example Application
   
   https://github.com/homicki/grails-h7-inheritance-repro
   
   ### Version
   
   8.0.0-RC1


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to