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