-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Using default @DiscriminatorValue for type CHAR is not safe
PostPosted: Mon Sep 15, 2008 3:11 pm 
Newbie

Joined: Wed Apr 02, 2008 3:52 pm
Posts: 3
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?


Top
 Profile  
 
 Post subject: I will file a bug on JIRA because there has been no response
PostPosted: Mon Oct 13, 2008 3:19 pm 
Newbie

Joined: Wed Apr 02, 2008 3:52 pm
Posts: 3
I will file a bug on JIRA because there has been no response.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.