Issue Type: Bug Bug
Affects Versions: 4.1.1
Assignee: Unassigned
Attachments: model.7z
Components: annotations
Created: 26/Oct/12 1:57 AM
Description:

When having a @OneToMany annotation on an entity and later changing that to @ManyToMany, Hibernate does not drop the unique constraint. It simply leaves the constraint intact.

Dropping and letting Hibernate regenerate the table does not add the unique constraint (works as expected). This means you'll not be able to insert multiple entries in the table, unless you regenerate it.

Created Table thus far:

CREATE TABLE A_B (
	A_id INT NOT NULL,
	b_id INT NOT NULL,
	CONSTRAINT PK__A_B__B54FFDE90F6D37F0 PRIMARY KEY (A_id, b_id) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = OFF, ALLOW_PAGE_LOCKS = OFF)

)
GO

CREATE UNIQUE INDEX UQ__A_B__4E29C30C1249A49B ON A_B (b_id ASC)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = OFF, ALLOW_PAGE_LOCKS = OFF)
GO
)

Likewise, changing @ManyToMany to @OneToMany will add a unique constraint. Inserting multiple values will however work fine.

Re-generating the table will add the constraint just fine.

SQL thus far:

CREATE TABLE A_B (
	A_id INT NOT NULL,
	b_id INT NOT NULL,
	CONSTRAINT PK__A_B__B54FFDE905E3CDB6 PRIMARY KEY (A_id, b_id) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
)
GO

Attached are the pretty basic entities I've used to confirm this behaviour.

Environment: Hibernate 4.1.1, bundled with JBoss AS 7.1.1
Microsoft SQL Server 2008
Project: Hibernate ORM
Labels: sqlserver metamodel
Priority: Minor Minor
Reporter: Marcus Bauer
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira