Hibernate constraint ConstraintViolationException. Is there an easy way to ignore duplicate entries?
Posted
by vincent
on Stack Overflow
See other posts from Stack Overflow
or by vincent
Published on 2010-05-23T23:35:09Z
Indexed on
2010/05/23
23:40 UTC
Read the original article
Hit count: 329
Basically I've got the below schema and I'm inserting records if they don't exists. However when it comes to inserting a duplicate it throws and error as I would expect. My question is whether there is an easy way to make Hibernate to just ignore inserts which would in effect insert duplicates?
CREATE TABLE IF NOT EXISTS `method` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`name` varchar(10) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
SEVERE: Duplicate entry 'GET' for key 'name'
Exception in thread "pool-11-thread-4" org.hibernate.exception.ConstraintViolationException: could not insert:
© Stack Overflow or respective owner