2 Replies Latest reply on May 19, 2006 9:42 AM by Emmanuel Bernard

    @AttirbuteOverride and unique contraints

    Pieter-Jan Malfait Newbie

      i'm trying to override a unique constraint on a column on a subclass, but it doesn't seem to work

      parent class:

      @MappedSuperclass
      public class BaseEntity {
      
       private Integer code;
      
       @Column(length=6,unique=true)
       public Integer getCode() {
       return code;
       }
       public void setCode(Integer code) {
       this.code = code;
       }
      
      }
      


      child class (with one class between them in de hierarchy)

      @Entity
      @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
      @AttributeOverride(name="code",column=@Column(unique=false))
      public abstract class InternDocument extends Document{
      }
      


      I can't persist two instances of a subclass of InternDocument with the same value for the code property...
      Anyone knows what my problem could be ?

      i looked around for a solution and stumbled on this JIRA issue:
      http://opensource.atlassian.com/projects/hibernate/browse/ANN-240

      which mentions exactly the same problem (can't override attributes on non-leave classes in the hierarchy) but it was solved in Hibernate Annotations in February, could it be that the error still exists in my config which is JBoss 4.0.3SP1 + EJB 3.0 RC4 PFD ?

        • 1. Re: @AttirbuteOverride and unique contraints
          Pieter-Jan Malfait Newbie

          i'm been trying to solve this some more and it seems that the @AttributeOverride annotation is ignored altogether..

          I've tried to put it on various classes in the class hierarchy including both @MappedSuperclass and @Entity , both leave and non-leave classes. I tried overriding the name of the column, the nullability, the uniqueness etc. Even if i try to override some column "THISCOLUMNDOESNTEXIST" , i have no error or message whatsoever..

          the class hierarchy is :

          (@MappedSuperclass) BaseEntity -> (@Entity) Document -> (@Entity) InternDocument -> (@Entity) LeaveDocument

          none of the following works :

          @Entity
          @AttributeOverride(name="code",column=@Column(nullable=false))
          public class LeaveDocument extends InternDocument {


          @Entity
          @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
          @AttributeOverride(name="code",column=@Column(name="anothercode"))
          public abstract class InternDocument extends Document{


          @Entity
          @Inheritance(strategy=javax.persistence.InheritanceType.TABLE_PER_CLASS)
          @AttributeOverride(name="THISCOLUMNDOESNEXIST",column=@Column(nullable=false))
          public abstract class Document extends BaseEntity {


          • 2. Re: @AttirbuteOverride and unique contraints
            Emmanuel Bernard Master

            I have some unit tests for that but if you can build a minimal runnable test case to reproduce it, I'll have a look. Be sure to use the latest versions.

            http://opensource.atlassian.com/projects/hibernate/secure/Dashboard.jspa