-->
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: creation of UNIQUE INDEX revisted
PostPosted: Wed Sep 14, 2005 6:29 am 
Newbie

Joined: Sun Mar 06, 2005 10:08 pm
Posts: 3
Hibernate version: 3.0.5

Name and version of the database you are using: MS SQL Server

I've reviewed earlier posts on this subject but I'm not sure a solution has been offered.

I am trying to find the appropriate mapping code to make SchemaExport emit DDL of the form:
Code:
CREATE UNIQUE INDEX i ON t (c1, c2, ...)


Using unique="true" in <properties> results in a column constraint:
Code:
<property name="foo" column="FOO" type="string" unique="true"/>

=>
Code:
FOO varchar(255) null unique,


Using index="x" in <properties> results in a non-unique index created:
Code:
<property name="foo" column="FOO" type="string" index="idx1"/>
<property name="bar" column="BAR" type="string" index="idx1"/>

=>
Code:
FOO varchar(255) null,
BAR varchar(255) null,
create index idx1 on TEST (FOO, BAR);


Using unique-key="x" in <properties> results in a table constraint:
Code:
<property name="foo" column="FOO" type="string" unique-key="uk1"/>
<property name="bar" column="BAR" type="string" unique-key="uk1"/>

=>
Code:
FOO varchar(255) null,
BAR varchar(255) null,
unique(FOO, BAR),


None of the above approaches work to create an explicit unique index.

What seems to be missing is a unique-index="x" attribute for <properties>, which would work like index="x" but generate `create UNIQUE index' instead of `create index'. I've checked the DTD and didn't find anythig else to try. I know that under MS SQL Server a table constraint like `unique(c1, c2, ...)' creates an internal index as a side effect, but it is not the same as an explicit index (it cannot be dropped and re-created), and in general implicit behaviour like this is not portable.

Any suggestions or workarounds gratefully received.
Thanks,
Nick


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.