Hibernate @DiscriminatorColumn and problem @DiscriminatorValue

I have this parent class:

@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "BSEntity")
@DiscriminatorColumn(name = "resourceType", discriminatorType = DiscriminatorType.STRING, length = 32)
public abstract class BaseEntity {

and subclass

@Entity
@Table(name = "BSCategory")
@DiscriminatorValue("Category")
public class CategoryEntity extends BaseEntity {

But when I run the program, I get the following error:

2010-06-03 10:13:54,222 [main] WARN  (org.hibernate.util.JDBCExceptionReporter:100) - SQL Error: 1364, SQLState: HY000
2010-06-03 10:13:54,222 [main] ERROR (org.hibernate.util.JDBCExceptionReporter:101) - Field 'resourceType' doesn't have a default value

Any thoughts?

Updated: The database is MySQL. I also changed the inheritance strategy for JOINED instead of SINGLE_TABLE. Help

Another update: I saw the following post somewhere, and it looks very interesting: http://opensource.atlassian.com/projects/hibernate/browse/ANN-140

New update: If I were to use the SecondaryTable approach, how could I continue?

Final update: it turns out that the @Discriminator problem does not work with sleep mode. I used the @SecondaryTable approach and took care of this for me. Thanks everyone for helping me!

+3
2

, , @DiscriminatorColumn @DiscriminatorValue . , , ?

, , InheritanceType.JOINED . , InheritanceType.SINGLE_TABLE.

http://docs.jboss.org/hibernate/stable/annotations/reference/en/html_single/#d0e1168

+2

.

, hbm2ddl.auto ( update), hibernate () .

UPDATE. . .

0

Source: https://habr.com/ru/post/1748360/


All Articles