2

I have an entity hierarchy based on hibernate strategy SINGLE_TABLE and I set ddl-auto=update in my application.yml.

When I run tests, using h2db, I get "NULL not allowed for column ".

This is my mapping:

==================
Shape      
    |--> Square
    |--> Cube
==================


@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "IS_SOLID", discriminatorType = DiscriminatorType.INTEGER)
@DiscriminatorValue(value = "-1")
public abstract class Shape{
...
}

@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorValue(value = "null")
public class Square extends Shape{
...
}


 @Entity
 @Inheritance(strategy=InheritanceType.SINGLE_TABLE)
 @DiscriminatorValue(value = "1")
 public class Cube extends Shape{
 ...
 }

I need to set null as discriminatorValue to one subclass.

When ddl-auto=update directive creates the shape table, it sets to not null the discriminator column, so I get "NULL not allowed for column ".

Is there a way to force the discriminator column to nullable using ddl-auto?

Fabio Formosa
  • 904
  • 8
  • 27
  • have you found a solution for it? – zibi Jul 30 '18 at 13:54
  • No, not by annotation. Only a workaround for my specific scenario: I wrote an "alter table" in method "before" of my junit test to remove `not null` at the descriminator column. – Fabio Formosa Jul 30 '18 at 14:36

1 Answers1

0

You can specify it using the columnDefinition property of @DiscriminatorColumn

@DiscriminatorColumn(name = "IS_SOLID", discriminatorType = 
                     DiscriminatorType.INTEGER, columnDefinition = "INT(1) NULL")
Plog
  • 9,164
  • 5
  • 41
  • 66