Reputation: 1094
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?
Upvotes: 2
Views: 2373
Reputation: 9612
You can specify it using the columnDefinition property of @DiscriminatorColumn
@DiscriminatorColumn(name = "IS_SOLID", discriminatorType =
DiscriminatorType.INTEGER, columnDefinition = "INT(1) NULL")
Upvotes: 0