PSQLException: ERROR: duplicate key value violates...

Questions and answers regarding general SQL and backend databases

PSQLException: ERROR: duplicate key value violates...

Postby tgs » Mon Feb 13, 2012 1:26 pm

In the Smart Client I get an Error while creating a new record:
Code: Select all
org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "calls_pkey"
     Detail: Key (uid_call)=(650) already exists.
       at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2102)
       at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1835)
       at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257)
       at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:500)
       at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:388)
       at org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:334)
       at sun.reflect.GeneratedMethodAccessor32.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:597)
       at com.servoy.j2db.Za.Zg.invoke(Zg.java:11)
       at $Proxy0.executeUpdate(Unknown Source)
       at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105)
       at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105)
       at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105)
       at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105)
       at com.servoy.j2db.dataprocessing.Zv.Za(Zv.java:591)
       at com.servoy.j2db.dataprocessing.Zv.performUpdates(Zv.java:980)
       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:597)
       at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:303)
       at sun.rmi.transport.Transport$1.run(Transport.java:159)
       at java.security.AccessController.doPrivileged(Native Method)
       at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
       at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
       at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
       at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
       at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
       at java.lang.Thread.run(Thread.java:680)

The pk of the table "calls" is "uid_call" and set as servoy sequence, step 1, not null. Last pk-id = 650 (in the table) and as next value is displayed in the developer 651, but it seems that the Servoy App Server don't take the 651, but the 650!?
I have updated the servoy sequences of all tables of the server on the servoy-admin site, but still the same error.
If I run the solution in the debug client from the developer, connected to the same database server, I don't get the error!?

Servoy 6.0.5
PostgreSQL 9.1.2 (Mac OS X 10.6.8 )
Java 1.6_29
Mac OS X 10.7.3

Regards
Thomas Schnaus
SAN Developer
yomotec GmbH
User avatar
tgs
 
Posts: 886
Joined: Wed Oct 04, 2006 12:05 pm
Location: Germany

Re: PSQLException: ERROR: duplicate key value violates...

Postby jcompagner » Mon Feb 13, 2012 6:35 pm

it does seems that your app server sequences are out of sync
The developer uses a select max(id) so that will work fine
Problem is that you can't mix the same database server with your developer.. Because then if you create new records in your developer, your application server sequences are out of sync
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8833
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet


Return to SQL Databases

Who is online

Users browsing this forum: No registered users and 19 guests

cron