Hi All-
I am trying to specify my own name for a unique constraint, however, hibernate and/or JPA is not taking it into account, the constraint does get created, but with a random provider (SQLServer 2005) chosen name.
Here is my entity:
Code:
@Entity
@Table(name = "TEST_TABLE1", uniqueConstraints = {
@UniqueConstraint(name="UQ__TESTTABLE1__NAME", columnNames={"NAME"})})
public class MyTest {
private Long id;
private String name;
/**
* @return the id
*/
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "ID")
public Long getId() {
return id;
}
/**
* @param id
* the id to set
*/
public void setId(Long id) {
this.id = id;
}
/**
* @return the name
*/
@Column(name = "NAME", nullable = false)
public String getName() {
return name;
}
/**
* @param name
* the name to set
*/
public void setName(String name) {
this.name = name;
}
}
The constraint looks like this:
Code:
UQ__TEST_TABLE1__2CC890AD (Unique, Non-Clustered)
The reason this is big deal for me is I need to catch Hibernate's CVH and notify the user exactly which column (property) the Edit failed. I am parsing the the SQLException for specific Constraint Names.
Can anybody please tell me what am I missing?
Thank you.