How to create an exception like this java.sql.BatchUpdateException: Duplicate entry?

sifynm
Tera Expert

                  I am trying to recreate an exception like this java.sql.BatchUpdateException: Duplicate entry '0046b3f6bb927240f3611272dbdb75b8' for key 'PRIMARY' -   I happened to find the solution for the same mentioned here: https://community.servicenow.com/thread/230668, but I would like to know what made this exception and I need to do to get an error message likewise.

1 ACCEPTED SOLUTION

sergiu_panaite
ServiceNow Employee
ServiceNow Employee

In the exception you posted, the duplicate key is 'PRIMARY' which is a unique index on sys_id column (as this column is marked as PRIMARY KEY).



To reproduce this:


- have a before insert business where you use current.update()



that's the easiest way to reproduce probably.


View solution in original post

5 REPLIES 5

Chuck Tomasi
Tera Patron

That particular message indicates that you are trying to create a record with the same sys_id as another record. The primary key on pretty much every table is the sys_id field and is marked as unique. You definitely don't want duplicate sys_ids in your system.



Can I understand why you want to recreate it? What is the objective here?


Chandu Telu
Tera Guru
Tera Guru

Hi Nadhan,




Please find the below links it may help you



java.sql.BatchUpdateException: Duplicate entry 'incident-priority' for key 'name'


error - java.sql.BatchUpdateException: Duplicate entry '72d13d6b1c0d05000d702ab289b4823b-test' for k...


java.sql.BatchUpdateException: Duplicate entry



Please provide your feedback appropriately (Like, Helpful, Endorse AND/OR Correct) to help community.




Thanks


Chandu Telu


sergiu_panaite
ServiceNow Employee
ServiceNow Employee

In the exception you posted, the duplicate key is 'PRIMARY' which is a unique index on sys_id column (as this column is marked as PRIMARY KEY).



To reproduce this:


- have a before insert business where you use current.update()



that's the easiest way to reproduce probably.


Thank you! I was having this exception pop up because I was using current.update() on a before insert Business Rule.