-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: False Integrity Constraint Violation
PostPosted: Sat Aug 01, 2009 6:33 pm 
Newbie

Joined: Tue Jul 14, 2009 2:16 pm
Posts: 6
I have a Pojo annotated as follows:

Code:
@Entity
@Table(name="detail_view_data")
public class DetailViewResponse {
   
   @Id @GeneratedValue(strategy=GenerationType.IDENTITY)
   @Column(unique=true,nullable=false,updatable=false,name="pd_id")
   private long id;
   

   @JoinColumn(name="person_id",unique=false)
   @OneToOne(optional=false,fetch=FetchType.LAZY)
   private Person subject;
   
   @JoinColumn(name="field_id",unique=false)
   @ManyToOne(optional=false,fetch=FetchType.EAGER)
   private DetailViewField field;
   
   private String value;
   
   @Temporal(value=TemporalType.TIMESTAMP)
   private Date dateEntered;



When I try to do an update or an insert on this, it throws an "integrity constraint violation exception", saying that there is a duplicate key in my "person_id" column (where I store 'subject'). I was under the impression that the annotation unique=false means that it is OK for there to be duplicate keys in that column. I didn't add the unique=false until after I started getting the error because I've never had to deal with this before.

I'm letting hibernate create my tables for me, so I've tried going into the database manually and dropping the tables to let hibernate recreate them, but it still doesn't work. For consistency's sake, here is the exception:

Code:
class org.springframework.dao.DataIntegrityViolationException :: could not insert: [net.frontlinesms.plugins.medic.data.domain.DetailViewResponse]; nested exception is org.hibernate.exception.ConstraintViolationException: could not insert: [net.frontlinesms.plugins.medic.data.domain.DetailViewResponse]
   at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:636)
   at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
   at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:424)
   at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
   at org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:694)
   at net.frontlinesms.data.repository.hibernate.BaseHibernateDao.saveWithoutDuplicateHandling(BaseHibernateDao.java:50)
   at net.frontlinesms.plugins.medic.data.repository.hibernate.HibernateDetailViewResponseDao.saveDetailViewResponse(HibernateDetailViewResponseDao.java:50)
   at net.frontlinesms.plugins.medic.ui.DetailedViewController.validateAndSaveResponses(DetailedViewController.java:229)
   at net.frontlinesms.plugins.medic.ui.DetailedViewController.editDataButtonClicked(DetailedViewController.java:213)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at thinlet.Thinlet.invokeImpl(Thinlet.java:4603)
   at thinlet.Thinlet.invoke(Thinlet.java:4572)
   at thinlet.Thinlet.handleMouseEvent(Thinlet.java:3855)
   at thinlet.Thinlet.processEvent(Thinlet.java:2970)
   at java.awt.Component.dispatchEventImpl(Component.java:4068)
   at java.awt.Container.dispatchEventImpl(Container.java:2068)
   at java.awt.Component.dispatchEvent(Component.java:3903)
   at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4256)
   at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3936)
   at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3866)
   at java.awt.Container.dispatchEventImpl(Container.java:2054)
   at java.awt.Window.dispatchEventImpl(Window.java:1801)
   at java.awt.Component.dispatchEvent(Component.java:3903)
   at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
   at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:269)
   at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:184)
   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:176)
   at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
Caused by: class org.hibernate.exception.ConstraintViolationException :: could not insert: [net.frontlinesms.plugins.medic.data.domain.DetailViewResponse]
   at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:94)
   at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
   at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:64)
   at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2186)
   at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2666)
   at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:71)
   at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
   at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:321)
   at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:204)
   at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:130)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210)
   at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:56)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195)
   at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:50)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
   at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:562)
   at org.hibernate.impl.SessionImpl.save(SessionImpl.java:550)
   at org.hibernate.impl.SessionImpl.save(SessionImpl.java:546)
   at org.springframework.orm.hibernate3.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:697)
   at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:419)
   at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
   at org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:694)
   at net.frontlinesms.data.repository.hibernate.BaseHibernateDao.saveWithoutDuplicateHandling(BaseHibernateDao.java:50)
   at net.frontlinesms.plugins.medic.data.repository.hibernate.HibernateDetailViewResponseDao.saveDetailViewResponse(HibernateDetailViewResponseDao.java:50)
   at net.frontlinesms.plugins.medic.ui.DetailedViewController.validateAndSaveResponses(DetailedViewController.java:229)
   at net.frontlinesms.plugins.medic.ui.DetailedViewController.editDataButtonClicked(DetailedViewController.java:213)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at thinlet.Thinlet.invokeImpl(Thinlet.java:4603)
   at thinlet.Thinlet.invoke(Thinlet.java:4572)
   at thinlet.Thinlet.handleMouseEvent(Thinlet.java:3855)
   at thinlet.Thinlet.processEvent(Thinlet.java:2970)
   at java.awt.Component.dispatchEventImpl(Component.java:4068)
   at java.awt.Container.dispatchEventImpl(Container.java:2068)
   at java.awt.Component.dispatchEvent(Component.java:3903)
   at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4256)
   at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3936)
   at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3866)
   at java.awt.Container.dispatchEventImpl(Container.java:2054)
   at java.awt.Window.dispatchEventImpl(Window.java:1801)
   at java.awt.Component.dispatchEvent(Component.java:3903)
   at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
   at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:269)
   at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:184)
   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:176)
   at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
Caused by: class com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException :: Duplicate entry '1453' for key 3
   at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:931)
   at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
   at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
   at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
   at com.mysql.jdbc.Connection.execSQL(Connection.java:3283)
   at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1332)
   at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1604)
   at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1519)
   at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1504)
   at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:94)
   at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:57)
   at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2186)
   at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2666)
   at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:71)
   at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
   at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:321)
   at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:204)
   at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:130)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210)
   at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:56)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195)
   at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:50)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
   at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:562)
   at org.hibernate.impl.SessionImpl.save(SessionImpl.java:550)
   at org.hibernate.impl.SessionImpl.save(SessionImpl.java:546)
   at org.springframework.orm.hibernate3.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:697)
   at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:419)
   at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
   at org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:694)
   at net.frontlinesms.data.repository.hibernate.BaseHibernateDao.saveWithoutDuplicateHandling(BaseHibernateDao.java:50)
   at net.frontlinesms.plugins.medic.data.repository.hibernate.HibernateDetailViewResponseDao.saveDetailViewResponse(HibernateDetailViewResponseDao.java:50)
   at net.frontlinesms.plugins.medic.ui.DetailedViewController.validateAndSaveResponses(DetailedViewController.java:229)
   at net.frontlinesms.plugins.medic.ui.DetailedViewController.editDataButtonClicked(DetailedViewController.java:213)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at thinlet.Thinlet.invokeImpl(Thinlet.java:4603)
   at thinlet.Thinlet.invoke(Thinlet.java:4572)
   at thinlet.Thinlet.handleMouseEvent(Thinlet.java:3855)
   at thinlet.Thinlet.processEvent(Thinlet.java:2970)
   at java.awt.Component.dispatchEventImpl(Component.java:4068)
   at java.awt.Container.dispatchEventImpl(Container.java:2068)
   at java.awt.Component.dispatchEvent(Component.java:3903)
   at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4256)
   at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3936)
   at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3866)
   at java.awt.Container.dispatchEventImpl(Container.java:2054)
   at java.awt.Window.dispatchEventImpl(Window.java:1801)
   at java.awt.Component.dispatchEvent(Component.java:3903)
   at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
   at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:269)
   at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:184)
   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:176)
   at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.