1 Reply Latest reply on Jan 29, 2007 4:45 PM by fhh

    Bug? @Inheritance(strategy=JOINED) AND @DiscriminatorValue d

      Hello!

      It seems that the the JBoss EJB3/Hibernate stuff ignores the @DiscriminatorValue annotation on JOIND inheritances:

      @Entity
      @Inheritance(strategy=JOINED)
      public abstract class parent {
      
       @Id
       Integer id;
      
      }
      
      @Entity
      @DiscriminatorValue("child")
      public class child extends parent {
      
       private String value;
      
      }
      


      If I read the documentation correctly the table parent should have a column DTYPE and for every persited child object it should have the value child.

      I know this value is not actually necessary since I could simply inner join child and parent but this becomes inefficient if more than a couple of classes extend parent. And it is unefficient if all I'm interested in is some aggregation of values in parent.

      I am not sured if support for discriminator column is required by the specs but Toplink ( http://www.oracle.com/technology/products/ias/toplink/jpa/howto/use-inheritance.html ) and Kodo http://docs.solarmetric.com/full/html/ejb3_overview_mapping_discrim.html support this. To me this seems like a bug because it makes the inheritance strategy JOINED far less useful.

      Regards

      Felix[/url]

        • 1. Re: Bug? @Inheritance(strategy=JOINED) AND @DiscriminatorVal

          Sorry, I have found the Hibernate bug describing this: http://opensource.atlassian.com/projects/hibernate/browse/ANN-140?page=all

          (It is amazing that you always find the bug report only after you tried to describe the problem yourself.)

          Since I don't know anything about the hibernate sources I will not even try to supply the 3k lines mentioned in the bug report but I have a dirty little workaround:

          @Entity
          @Inheritance(strategy=JOINED)
          //@DiscriminatorColumn(name="YOUR_DTYPE")
          public abstract class parent {
          
           @Id
           Integer id;
          
           @Column(name="YOUR_DTYPE",length=31)
           public String getDiscriminatorValue() {
          
           DiscriminatorValue discriminatorValueAnnotation = this.getClass().getAnnotation(DiscriminatorValue.class);
          
           if (discriminatorValueAnnotation != null) {
           return discriminatorValueAnnotation.value();
           }
          
           return this.getClass().getSimpleName();
           }
          
           public void setDiscriminatorValue(String dummy) {
           }
          
          }
          


          It is double plus unbeautiful but it works. Should this ever be fixed you can simply remove the workaround and everything should work as expected.

          Regards

          Felix