2

I have class A with subclasses B and C.
I am using InheritanceType.SINGLE_TABLE and one column, type, is being used as DiscriminatorColumn.

Earlier, class B has DiscriminatorValue("1") and class C has DiscriminatorValue("2"). I have some 100+ entries in the table and all was working fine.

Now, I have created one more subclass of A, D. But I wanted it to have DiscriminatorValue("1"), so I changed DiscriminatorValues of B and C to 2 and 4 respectively.
I also updated the database column type with appropriate values.

But now when I run the application, I am getting following exception:

org.hibernate.WrongClassException: Object with id: 9 was not of the 
specified subclass: com.example.D (Discriminator: 1)

What would be the problem?

sachinpkale
  • 989
  • 3
  • 14
  • 35

2 Answers2

3

Never mind. I figured out the problem. The entry for class D in persistence.xml file was missing. Now, its working fine.

sachinpkale
  • 989
  • 3
  • 14
  • 35
1

In my case, I was adding some hard-coded values to the database and I wrote "Guest" for discriminator value in insertion queries.

My mistake was that I annotated Guest class to have "guest" (small 'g') as discriminator value, and added guests into database with "Guest" discriminator value.

Good link with a few possible solutions: here

I really hope that this helps someone.

Filip Savic
  • 2,737
  • 1
  • 29
  • 34