Org.hibernate.exception.ConstraintViolationException: JDBC batch update failed

In my module that I'm working on, I got this error, which is said to be caused by org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update and java.sql.BatchUpdateException (full stack trace is here: click here ) .

From what I read from other posts, this is certainly caused by a primary key violation. However, I could not even reproduce the problem, so that I could at least trace the real error and solve the problem. Each time I inserted an identical record with one that is already in the database, it will simply merge with each other and without errors. However, I was getting a lot of this deployment error, so I'm not quite sure what is happening on the deployment server (I'm just a student student, so I still love "noob").

I would appreciate it if someone could point me in the direction. Thank you (Let me know if something needs to be added)

Here is a fragment of hibernation display for a module (I hope this helps):

 <hibernate-mapping package="edu.umd.cattlab.schema.cattXML.extensions.VaTraffic" default-lazy="false" default-cascade="all, delete-orphan" schema="vatraffic"> <typedef class="edu.umd.cattlab.schema.hibernate.util.XMLGregorianCalendarType" name="XMLCal"/> <class name="VaTrafficAssociatedEvent" table="associated_event"> <id name="associatedEventId" column="associated_event_id"> <generator class="sequence"> <param name="sequence">ritis.associated_event_id_seq</param> </generator> </id> <property name="secondaryEventId" column="secondary_event_id" not-null="true" /> <property name="unassociatedTimestamp" type="XMLCal" column="unassociated" /> <property name="autoRelated" column="auto_related" not-null="true" /> <many-to-one name="relationshipType" column="relationship_type" not-null="true" cascade="none" /> </class> 

This is the part of Java code that uses the above mapping: click here

+4
source share
2 answers

You may have more restrictions than the primary key restriction. Maybe you have a foreign key constraint that you violate? Or perhaps a restriction on multiple columns. Could you enable DDL for the table you are updating?

+3
source

When looking at logs, this is a violation of the pk restriction. In particular, ERROR: the duplicate key violates the unique constraint "associated_event_pk"

Trying to determine why this is happening can be a deep dive, but first, how do you generate the values ​​for this field? In your ddl, it appears as the "nextval" field, but your log shows that there is an explicit value. Where did this meaning come from? Why don't you let postgre set the value itself?

+2
source

All Articles