-->
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.  [ 24 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Can Hibernate generate indexes from mapping files?
PostPosted: Mon May 03, 2004 11:38 am 
Beginner
Beginner

Joined: Sun Oct 05, 2003 9:07 am
Posts: 47
I'm getting ready to move into production on a Hibernate-based application. As part of that move, we are moving from a MySQL database to DB2/AS400. Hibernate made this a snap - so first of all, thanks for such an awesome tool.

For now, I'm creating the database using the <schemaexport> ant task - which reads from my XDoclet-generated .hbm.xml files. The DBA on the 400 noticed that no indexes where created, which makes sense. When I run <schemaexport> in MySQL, I see indexes being created, but I'm assuming those are simply for the foreign key constraints?

I know its possible to map columns to pre-existing indexes, but I'm wondering if its possible to generate those indexes in the first place (using Ant/XDoclet/etc.)? Or do all indexes (particularly multi-column) need to be created manually?

Thanks,

Matt


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 03, 2004 11:39 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
There is an index attribute. Check the DTD


Top
 Profile  
 
 Post subject: index only applies to columns?
PostPosted: Mon May 03, 2004 11:54 am 
Beginner
Beginner

Joined: Sun Oct 05, 2003 9:07 am
Posts: 47
gavin wrote:
There is an index attribute. Check the DTD


I saw that, and looking at the DTD:

Code:
<!-- Declares the type and column mapping for a collection index (array or
list index, or key of a map). -->

<!ELEMENT index (column*)>
  <!ATTLIST index column CDATA #IMPLIED>
  <!ATTLIST index type CDATA #IMPLIED>      <!-- required for maps -->
  <!ATTLIST index length CDATA #IMPLIED>


It looks like it can only be applied to columns. I guess I'm looking for a @hibernate.index tag or something that'll create an index on the commonly accessed columns. For example:

Code:
@hibernate.index properties="username,firstName,lastName"


Or should this type of "index creation" be left to the DBA?

Thanks,

Matt


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 03, 2004 11:57 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
<!ATTLIST column index CDATA #IMPLIED>

You specify the name of the index on all three columns.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 03, 2004 12:01 pm 
Beginner
Beginner

Joined: Sun Oct 05, 2003 9:07 am
Posts: 47
I'll interpret that as:

"No, Hibernate's <schemaexport> task cannot create multi-column indexes for you. You can map your columns to a multi-column index, but it cannot create them for you."

Thanks,

Matt


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 03, 2004 12:02 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Of course it can, just as gavin said, put an index element with the same name on all included properties.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 03, 2004 12:03 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Wrong interpretation.

SchemaExport will create a multi-column index for you if specify index attributes.


Top
 Profile  
 
 Post subject: Very cool - and easy to do with XDoclet
PostPosted: Mon May 03, 2004 1:33 pm 
Beginner
Beginner

Joined: Sun Oct 05, 2003 9:07 am
Posts: 47
Nice. To create and use an index, I had to change:

@hibernate.property column="username" not-null="true"

to

@hibernate.property
@hibernate.column name="username" index="indexname" not-null="true"

Thanks,

Matt


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 09, 2004 6:56 am 
Newbie

Joined: Thu Sep 09, 2004 5:53 am
Posts: 2
Hi guys,

I'm pretty new to hibernate, from your conversation I understand how I can create a one-to-one index.

I was wondering does hibernate support mapping of one column to multiple indexes? such as:

column1
/**
* @hibernate.property
* @hibernate.column
* name="column1"
* index="index1"
**/

column2
/**
* @hibernate.property
* @hibernate.column
* name="column2"
* index="index1"
* index="index2"
**/


What I want to achieve is essentially the following script:
CREATE UNIQUE INDEX index1 ON store (
column1 ASC,
column2 ASC
);

CREATE INDEX index2 ON store (
column2 ASC
);

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 09, 2004 7:00 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Not possible at present.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 09, 2004 7:10 am 
Newbie

Joined: Thu Sep 09, 2004 5:53 am
Posts: 2
Wow that was quick, thanks for the prompt reply, Gavin.

One more thing, is it possible to say assign the id as index? if I were to use

@hibernate.id
generator-class="assigned"


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 23, 2005 10:00 am 
Regular
Regular

Joined: Mon Sep 20, 2004 8:42 am
Posts: 58
Location: Boston, US
mraible wrote :
Quote:
When I run <schemaexport> in MySQL, I see indexes being created, but I'm assuming those are simply for the foreign key constraints?


In Oracle, indexes are implicitly created only for Primary and Unique keys and not for Foreign keys. However for MySQL versions 4.1.2 and above they seem to be created implicitly for FK's as well.

Quote:
Starting with MySQL 4.1.2, these indexes are created automatically. In older versions, the indexes must be created explicitly or the creation of foreign key constraints fails.


As a general rule, all foreign keys should be indexed.

Sanjiv


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 26, 2005 7:42 pm 
Expert
Expert

Joined: Thu Jan 08, 2004 6:17 pm
Posts: 278
gavin wrote:
Not possible at present.


Is there any plan for making this possible? (Or has it since become possible, say in Hibernate 3?) We have a lot of use cases for a single column in multiple multi-column indexes.

If not, should I make a JIRA entry for it?

Cheers,
Rob


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 26, 2005 7:48 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
you may now use a comma-separated list of index names


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 26, 2005 7:55 pm 
Expert
Expert

Joined: Thu Jan 08, 2004 6:17 pm
Posts: 278
gavin wrote:
you may now use a comma-separated list of index names


In Hibernate 3 only, or is this also supported in Hibernate 2.1.8?

Thanks,
Rob


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 24 posts ]  Go to page 1, 2  Next

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.