mysql> alter table metakey add constraint Name unique(name);
mysql> desc metakey;
+-------+---------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------------------+------+-----+---------+----------------+
| id | bigint(20) unsigned | NO | PRI | NULL | auto_increment |
| name | varchar(45) | NO | UNI | | |
+-------+---------------------+------+-----+---------+----------------+
@Entity
@Table(name = "metakey",uniqueConstraints={@UniqueConstraint(name="Name",columnNames={"name"})})
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
public class MetaKey implements Serializable{
@Id @Column @GeneratedValue private Long id;
@Column private String name;
}
sess.save(obj);
..
}catch(ConstraintViolationException cve){
log.error(cve.getMessage());
log.info("Constraint name:"+cve.getConstraintName());
}
Я получаю их в журнале - cve.getConstraintName () возвращает ноль
org.hibernate.util.JDBCExceptionReporter - SQL Error: 1062, SQLState: 23000
org.hibernate.util.JDBCExceptionReporter - Duplicate entry 'Unit' for key 'Name'
could not insert: [com.comp.MetaKey]
Constraint name:null
Есть ли способ найти имя ограничения?
Версия сервера: 5.1.56Hibernate версия: 3.6