rishi
rishi

Reputation: 1842

discriminator column is not working with table per subclass

JARS usedHi All,

I am using discriminator column in table per subclass inheritence mapping. This is the entry of parent class

@Entity  
@Table(name = "employee105")
@Inheritance(strategy=InheritanceType.JOINED)   
@DiscriminatorColumn(name="emp_type" , discriminatorType= DiscriminatorType.STRING) 

and entries of subclass are as follows:

@Entity  
@Table(name="contractemployee105")
@DiscriminatorValue("P")
@PrimaryKeyJoinColumn(name="ID") 

@Entity  
@Table(name="regularemployee105")
@DiscriminatorValue("T")
@PrimaryKeyJoinColumn(name="ID") 

I know my code is correct and tables are being generated but in insert query discriminator column is not being created. I am using jars as shown in image. kindly let me know the issue. I suspect that this is the issue with JARS or hibernate version. thanks

Upvotes: 0

Views: 1502

Answers (2)

Don Roby
Don Roby

Reputation: 41127

It's likely as you suspect a problem with your hibernate version. Bug HHH-6911 was exactly this issue, and was resolved in Hibernate 4.2.9, 4.3.1. If your version of hibernate is earlier, you might want to upgrade. (Looking at your list of jars, this indeed appears to be the case.)

As noted in Stefan's answer, Hibernate doesn't need the discriminator in this case, but the JPA spec says it should be allowed and persisted if specified.

Upvotes: 1

Stefan Steinegger
Stefan Steinegger

Reputation: 64628

With table per subclass, you don't need a discriminator. Hibernate determines the subclass by finding a record in the relevant table.

Upvotes: 1

Related Questions