Issue Type: Improvement Improvement
Affects Versions: 3.6.0
Assignee: Unassigned
Components: annotations
Created: 17/Jan/13 6:38 AM
Description:

It would be useful to be able to define a @UniqueConstraint in a subclass of a an entity with a Single Table hierarchy strategy, so that new constraints referring columns of the subclass can be added.
Right now, we can add unique constraints in the subclass only if they involve a single column (with the element 'unique' of annotation '@Column'):

pubic MySubclass extends MyEntity
{

....

@Column(name = "IDENTIFIER", length = 100, nullable = false, unique = true)
public String getIdentifier()

{ return identifier; }

@Column(name = "PREFIX", length = 100, nullable = false)
public String getPrefix()

{ return prefix; }

}

Being a Single Table hierarchy, @Table annotation is defined in the hierarchy superclass, and @UniqueConstraint should be all defined there.
In order to define an UniqueConstraint in the subclass, we should declare @Table annotation twice, in the sublcass too, but it has no sense and Hibernate ignores this declaration, giving the warning "[org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:602)] WARN - Illegal use of @Table in a subclass of a SINGLE_TABLE hierarchy".

@Table(name = "MY_TABLE", uniqueConstraints = @UniqueConstraint(name = "UK_MY_TABLE_1", columnNames = { "IDENTIFIER", "PREFIX" }))
pubic MySubclass extends MyEntity

{ ... }

So we can define an unique constraint in a sublcass of a single table hierarchy only if they refers a single column!

Project: Hibernate ORM
Priority: Major Major
Reporter: Moretti Leonardo
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