Details
Assignee
UnassignedUnassignedReporter
Leonardo MorettiLeonardo MorettiComponents
Priority
Major
Details
Details
Assignee
Unassigned
UnassignedReporter
Leonardo Moretti
Leonardo MorettiComponents
Priority
Created January 17, 2013 at 2:38 PM
Updated April 22, 2015 at 6:24 PM
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!