This exception is thrown from the following code in EntityBinder.java in Hibernate:
public void bindDiscriminatorValue() {
if ( StringHelper.isEmpty( discriminatorValue ) ) {
Value discriminator = persistentClass.getDiscriminator();
if ( discriminator == null ) {
persistentClass.setDiscriminatorValue( name );
}
else if ( "character".equals( discriminator.getType().getName() ) ) {
throw new AnnotationException("Using default @DiscriminatorValue for a discriminator of type CHAR is not safe");
}
else if ( "integer".equals( discriminator.getType().getName() ) ) {
persistentClass.setDiscriminatorValue( String.valueOf( name.hashCode() ) );
}
else {
persistentClass.setDiscriminatorValue( name ); //Spec compliant
}
}
else {
//persistentClass.getDiscriminator()
persistentClass.setDiscriminatorValue( discriminatorValue );
}
}
There is a reference to this problem on page 60 of JPA 101 by Chris Maki: "CAUTION: Although the JPA states that a DiscriminatorValue can be
specified on only a concrete entity, at the time of this writing, Hibernate generates an exception if you provide no value for an abstract entity ...
when the discriminator column type is CHAR."
The workaround is to add a bogus annotation to the abstract class:
@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="TYPE", discriminatorType=DiscriminatorType.CHAR, length=1)
@DiscriminatorValue(<bogus character value here to work around Hibernate bug>)
@EntityListeners(CustomFieldDefinitionListener.class)
public abstract class MyAbstractClass implements...
I can't find a reference to this problem on JIRA (Chris says he did not file a bug on JIRA about this).
Should I file a bug on JIRA about this?
|