Reputation: 24192
i have a superclass that defines a name column:
@MappedSuperclass
public class SuperClass {
@Basic
private String name;
}
there are plenty of concrete @Entity subclasses that extend it, but for one of them i'd like to add a unique constraint on the name column. i cannot just add @Column(unique=true)
on the superclass, since thats not correct for all of its subclasses.
how do i redefine the name column in a subclass to be unique? (note: my model maps fields, not getter methods)
Upvotes: 2
Views: 885
Reputation: 340
try @AttributeOverride( name="name", column = @Column(name="new_name", unique=true) on your subclass. And then you have to change your column 'name' to 'new_name' in db for the table on which subclass is mapped
Upvotes: 2