-->
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.  [ 1 post ] 
Author Message
 Post subject: Indexing keys question
PostPosted: Fri Jul 17, 2009 12:40 pm 
Beginner
Beginner

Joined: Thu May 28, 2009 10:25 am
Posts: 21
What's the correct annotation to index by the fields below? Please point out what I'm doing wrong.
I'd prefer to use JPA annotations instead of the hibernate @Index annotation I'm playing with. Also, why do all the last 3 entries of my "show keys" output refer to "GROUPID


Thanks

Code:
mysql> describe metrics;
+-----------+--------------+------+-----+---------+----------------+
| Field     | Type         | Null | Key | Default | Extra          |
+-----------+--------------+------+-----+---------+----------------+
| ID        | bigint(20)   | NO   | PRI | NULL    | auto_increment |
| DOCS      | int(11)      | YES  |     | NULL    |                |
| GROUPID   | bigint(20)   | YES  | MUL | NULL    |                |===========> need to index by this column
| GROUPTYPE | char(1)      | YES  |     | NULL    |                |===========> need to index by this column
| PAGES     | int(11)      | YES  |     | NULL    |                |
| SIZE      | int(11)      | YES  |     | NULL    |                |
| TYPE      | varchar(255) | YES  |     | NULL    |                |===========> need to index by this column
+-----------+--------------+------+-----+---------+----------------+


Code:
mysql> show keys from  metrics;
+---------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| Table   | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment |
+---------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| metrics |          0 | PRIMARY  |            1 | ID          | A         |           0 |     NULL | NULL   |      | BTREE      |         |
| metrics |          0 | GROUPID  |            1 | GROUPID     | A         |           0 |     NULL | NULL   | YES  | BTREE      |         |=======> refer to GROUPID
| metrics |          0 | GROUPID  |            2 | GROUPTYPE   | A         |           0 |     NULL | NULL   | YES  | BTREE      |         |=======> refer to GROUPID
| metrics |          0 | GROUPID  |            3 | TYPE        | A         |           0 |     NULL | NULL   | YES  | BTREE      |         |=======> refer to GROUPID


Code:
@Entity
@Table(name = "METRICS", uniqueConstraints = { @UniqueConstraint(columnNames = { "GROUPID", "GROUPTYPE", "TYPE" }) })
public class Metrics implements Serializable, IFieldsAccessibleAsString {

   /**
    *
    */
   private static final long serialVersionUID = 1L;
   @Id
   @Column(name = "ID")
   @GeneratedValue(strategy = GenerationType.AUTO)
   private long id;

   @Index(name = "GROUPID")
   @IndexColumn(name = "GROUPID")
   @Column(name = "GROUPID")
   private long groupId;

   @Index(name = "GROUPTYPE")
   @IndexColumn(name = "GROUPTYPE")
   @Column(name = "GROUPTYPE")
   private char groupType;

   @Index(name = "TYPE")
   @IndexColumn(name = "TYPE")
   @Column(name = "TYPE")
   private String type;

   @Column(name = "DOCS")
   private int docs;

   @Column(name = "PAGES")
   private int pages;

   @Column(name = "SIZE")
   private int size;
}



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

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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.