I have an entity annotated with the following:
@Entity
@Table(uniqueConstraints={@UniqueConstraint(columnNames={\"name\"})})
public class Component extends M
I would suggest attacking this problem from a different angle:
add a new column, internal one, call it lcname (stands for lower-cased name)
@NotEmpty
@Column(nullable = false)
private String lcname;
change the constraint you set as annotation to use the new field instead :
@Entity
@Table(uniqueConstraints={@UniqueConstraint(columnNames={"lcname"})})
public class Component extends Model {
...
}
modify the name setter to also set lcname with a lower case of the original name provided by the client
public void setName(String name) {
this.name = name;
this.lcname = name.toLowerCase();
}
That's it. Every time the entity will be persisted, also a lower cased name will be saved. That way if you save "A" you'll have a record with lcname = "a" saved, and next time you try to save an entity with name "a" the operation will fail due to the constraint on lcname The change is completely transparent to anyone who fetches an entity from the database since lcname is private and there is no getter for it, while the original getName will return the original name as provided initially by the client who created it.