Hi all. I'm new to hibernate and this seems like it should be simple but for the life of me I can't get a column indexed on my table. The two methods I've seen in docs are adding indexes in the Table annotation and just doing an Index annotation on a Column. I believe my sample below should do both of those. When I run this app, my table is created, but there are no indexes on STR1 or STR2:
mysql> describe TEST_INDEX;
+-------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+----------------+
| m_id | bigint(20) | NO | PRI | NULL | auto_increment |
| STR1 | varchar(255) | YES | | NULL | |
| STR2 | varchar(255) | YES | | NULL | |
+-------+--------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)
Any help would be greatly appreciated.
------------------------------------------------------------------------
Code:
@Entity
@Table(name="TEST_INDEX")
@org.hibernate.annotations.Table(
appliesTo = "TEST_INDEX",
indexes =
@org.hibernate.annotations.Index(
name = "IDX_STR1",
columnNames = { "STR1" }
)
)
public class TestIndex implements Serializable {
@Id @GeneratedValue
@Column
long m_id;
@Column(name="STR1")
String m_str1;
@Column(name="STR2")
@org.hibernate.annotations.Index(name = "IDX_STR2")
String m_str2;
/** Creates a new instance of TestIndex */
public TestIndex() {
m_str1 = "str1";
m_str2 = "str2";
}
public static void main(String args[]) {
Session session =
HibernateUtil.getSessionFactory().openSession();
Transaction tx = session.beginTransaction();
TestIndex node = new TestIndex();
session.save(node);
tx.commit();
session.close();
}
}