-->
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.  [ 3 posts ] 
Author Message
 Post subject: how to create a complex index for a table with two columns
PostPosted: Thu Jan 15, 2009 12:16 pm 
Newbie

Joined: Thu Jan 15, 2009 12:06 pm
Posts: 2
Hi,
I have a table with two columns for example a table test has two columns "id" and "name" where id is a primary key

Now I need to create a complex index for both the columns but priority must be (name,id)

Following is the query to create this table.. But how do I represent it in .hbm.xml file.. Please help


CREATE TABLE `Test1`.`New Table` (

`id` INTEGER UNSIGNED NOT NULL DEFAULT NULL AUTO_INCREMENT,

`name` VARCHAR(45) NOT NULL,

PRIMARY KEY (`id`),

INDEX `Index_2`(`name`, `id`)

)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 15, 2009 3:23 pm 
Beginner
Beginner

Joined: Wed Apr 18, 2007 6:17 pm
Posts: 49
Location: Dominican Republic
Hello,

If you're using xml there it's an attribute named index that it's used to create the index on the associated property if you use the same name for two or more properties then it will create the index with those properties in the order that are declared.

If you're using annotation the attribute of @org.hibernate.annotations.Index with the name of the indexes and the columnames.

regards,


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 16, 2009 12:59 am 
Newbie

Joined: Thu Jan 15, 2009 12:06 pm
Posts: 2
Thank you.. I have tried this out.. My problem here is the order of the index columns.
But I need the order for the name column first and then the "id". But I am not able to do this as my id is the primary key and it hbm, this needs to be always declared first. Please let me know if there is any way for this Thanks in advance


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

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.