vandershraaf
vandershraaf

Reputation: 895

org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update

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

From what I've read from other posts, this is surely caused by violation of primary key. However I couldn't even replicate the problem so that I can at least trace the real bug and solve the problem. Every time I inserted an identical entry with the one which already in the database, it will simply merge with each other and no error. However, I was getting many of this error in the deployment, so I'm not quite sure what's going on in the deployment server (I'm just a student developer, so I'm still kinda 'noob' in this).

I would appreciate it even if anyone can point me to the direction. Thanks. (Inform me if there's something need to be added)

Here is the snippet of hibernate mapping for the module (hope this would help) :

<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 utilizes the above mapping: click here

Upvotes: 4

Views: 33599

Answers (2)

Taylor
Taylor

Reputation: 4086

In reviewing the logs, it is a violation of the pk constraint. Specifically ERROR: duplicate key violates unique constraint "associated_event_pk"

Trying to determine why this is happening may be a deep dive, but for starters how are you generating values for this field? In your ddl it shows as a "nextval" field but your log appears to indicate there is an explicit value. Where is this value coming from? Why are you not letting postgre set the value itself?

Upvotes: 2

JustinKSU
JustinKSU

Reputation: 4999

You can have more constraints than just a primary key constraint. Could it be you have a foreign key constraint that you are violating? Or maybe a multiple column unique constraint. Could you please include the DDL for the table you are updating?

Upvotes: 3

Related Questions