4 Replies Latest reply on Sep 1, 2005 12:33 PM by Emmanuel Bernard

    @Index

    J-C jc Apprentice

      I try to define an index using @Index (with mysql):
      I write :

      @Id(generate = GeneratorType.AUTO)
       public int getId() {
       return id;
       }
      
       @Index(name = "regionNameIndex")
       public String getName() {
       return name;
       }
      


      The index on the name is not created. How should I define my index ?



        • 1. Re: @Index
          Emmanuel Bernard Master

          It's a bug, I've fixed it in CVS.
          As a workaround, either use @Index at the class level or use explicitly @Column on elements you want to @Index

          • 2. Re: @Index
            J-C jc Apprentice

            I've try several workaround and none of them works:

            @Entity()
            @Table(name = "TaxonBO", indexes = { @Index(name = "idx", columnNames = { "mnemo" }) })
            public class TaxonBO ...
            

            or
            @Column(name="mnemo")
            @Index(name="idx")
            public String getMnemo() {
            ...
            }


            Is there another workaround ? Which class need to be patched to fix the bug ?

            • 3. Re: @Index
              J-C jc Apprentice

              It seems that this bug was referenced by:
              http://opensource2.atlassian.com/projects/hibernate/browse/ANN-32

              I've try to update my config to:
              (mysql, hbm3.1b2, annotations3.1b4).

              It still does not works. (Sorry to insist but for me that bug is a real problem. I try to bench EJB2/JDO2 vs EJB3/hibernate and without index it is not possible).

              • 4. Re: @Index
                Emmanuel Bernard Master

                Both workaround I gave you are working.

                But if you want to patch, patch AnnotationBinder

                @@ -810,7 +810,6 @@
                 Column ann = (Column) annotatedElt.getAnnotation(Column.class);
                 Formula formulaAnn = (Formula) annotatedElt.getAnnotation(Formula.class);
                 columns = Ejb3Column.buildColumnFromAnnotation(new Column[] { ann }, formulaAnn, nullability, propertyHolder, inferredData, entityBinder.getSecondaryTables(), mappings);
                - columns[0].addIndex( annotatedElt.getAnnotation( Index.class ) );
                 }
                 else if ( annotatedElt.isAnnotationPresent(Columns.class) ) {
                 Columns anns = annotatedElt.getAnnotation(Columns.class);
                @@ -842,6 +841,15 @@
                 if (columns == null ) {
                 columns = Ejb3Column.buildColumnFromAnnotation(null, null, nullability, propertyHolder, inferredData, entityBinder.getSecondaryTables(), mappings);
                 }
                +
                + //init index
                + Index index = annotatedElt.getAnnotation( Index.class );
                + if (index != null) {
                + for (Ejb3Column column : columns) {
                + column.addIndex( index );
                + }
                + }
                +
                 if (nullability == Nullability.FORCED_NOT_NULL) {
                 //force columns to not null
                 for (Ejb3Column col : columns) {


                "jc7442" wrote:
                It seems that this bug was referenced by:
                http://opensource2.atlassian.com/projects/hibernate/browse/ANN-32

                It's not the same, and this bug was a user misuse

                (Sorry to insist but for me that bug is a real problem. I try to bench EJB2/JDO2 vs EJB3/hibernate and without index it is not possible).


                If you are doing a benchmark, why don't you just let your DBA create/tune the the DDL statements for you like in most companies. Generated DDL is more a convenient tool for developpers.