Cannot Save Form Data

Since switching to Postgres, I have gone through our database tables and fixed primary keys that were based on text fields to use integer fields. That went smoothly. We did have a few tables that were already using integers for pk’s so not maintenance was necessary. We have a table that stores images we use for buttons. This was one of the tables I didn’t have to mess with. I know I’ve added rows to this table since the database switch, but for some reason today when I try to add a new record I get this error:

Cannot save form data
 > com.servoy.j2db.dataprocessing.DataException: ERROR: duplicate key value violates unique constraint "buttons_pkey"

Here is a copy of my server log:

2010-12-01 10:07	AWT-EventQueue-0	ERROR	com.servoy.j2db.util.Debug	Throwable

com.servoy.j2db.ApplicationException: Cannot save form data 
    	at com.servoy.j2db.dataprocessing.EditRecordList.stopEditing(EditRecordList.java:598) 
    	at com.servoy.j2db.dataprocessing.EditRecordList.stopEditing(EditRecordList.java:165) 
    	at com.servoy.j2db.smart.dataui.DataRenderer$1.mouseReleased(DataRenderer.java:112) 
    	at java.awt.Component.processMouseEvent(Unknown Source) 
    	at javax.swing.JComponent.processMouseEvent(Unknown Source) 
    	at java.awt.Component.processEvent(Unknown Source) 
    	at java.awt.Container.processEvent(Unknown Source) 
    	at java.awt.Component.dispatchEventImpl(Unknown Source) 
    	at java.awt.Container.dispatchEventImpl(Unknown Source) 
    	at java.awt.Component.dispatchEvent(Unknown Source) 
    	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) 
    	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) 
    	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) 
    	at java.awt.Container.dispatchEventImpl(Unknown Source) 
    	at java.awt.Window.dispatchEventImpl(Unknown Source) 
    	at java.awt.Component.dispatchEvent(Unknown Source) 
    	at java.awt.EventQueue.dispatchEvent(Unknown Source) 
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) 
    	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) 
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) 
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source) 
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source) 
    	at java.awt.EventDispatchThread.run(Unknown Source) 
    Caused by: com.servoy.j2db.dataprocessing.DataException: ERROR: duplicate key value violates unique constraint "buttons_pkey" 
    	at com.servoy.j2db.dblayer.Zb.Za(Zb.java:119) 
    	at com.servoy.j2db.server.Zc.Zo.Za(Zo.java:442) 
    	at com.servoy.j2db.dataprocessing.Zu.performUpdates(Zu.java:396) 
    	at com.servoy.j2db.dataprocessing.EditRecordList.stopEditing(EditRecordList.java:464) 
    	... 22 more

2010-12-01 10:07	AWT-EventQueue-0	ERROR	com.servoy.j2db.util.Debug	Error executing sql: insert into buttons (bgcolor, fgcolor, enabled, tooltiptext, transparent, visible, buttonname, font, bgcolor_field, mainimagehtml, mainimage, pressedimage, pressedimagehtml, mainimageurl, mainimagecalc) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) with params: [NullValue with type: 12 ,type: com.servoy.j2db.dataprocessing.ValueFactory$NullValue, NullValue with type: 12 ,type: com.servoy.j2db.dataprocessing.ValueFactory$NullValue, NullValue with type: 4 ,type: com.servoy.j2db.dataprocessing.ValueFactory$NullValue, NullValue with type: 12 ,type: com.servoy.j2db.dataprocessing.ValueFactory$NullValue, NullValue with type: 4 ,type: com.servoy.j2db.dataprocessing.ValueFactory$NullValue, NullValue with type: 4 ,type: com.servoy.j2db.dataprocessing.ValueFactory$NullValue, NullValue with type: 12 ,type: com.servoy.j2db.dataprocessing.ValueFactory$NullValue, NullValue with type: 12 ,type: com.servoy.j2db.dataprocessing.ValueFactory$NullValue, NullValue with type: 12 ,type: com.servoy.j2db.dataprocessing.ValueFactory$NullValue, '<html><head></head><body><p style="margin-top: 0"><img src="media:///servoy_blobloader?servername=eclinic&tablename=buttons&dataprovider=mainimage&rowid=DbIdentValue26222912"></p></body></html>' ,type: java.lang.String, NullValue with type: -2 ,type: com.servoy.j2db.dataprocessing.ValueFactory$NullValue, NullValue with type: -2 ,type: com.servoy.j2db.dataprocessing.ValueFactory$NullValue, '<html><head></head><body><p style="margin-top: 0"><img src="media:///servoy_blobloader?servername=eclinic&tablename=buttons&dataprovider=pressedimage&rowid=DbIdentValue26222912"></p></body></html>' ,type: java.lang.String, 'media:///servoy_blobloader?servername=eclinic&tablename=buttons&dataprovider=mainimage&rowid=DbIdentValue26222912' ,type: java.lang.String, NullValue with type: -2 ,type: com.servoy.j2db.dataprocessing.ValueFactory$NullValue]

org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "buttons_pkey" 
    	at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1525) 
    	at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1309) 
    	at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:188) 
    	at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:452) 
    	at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:354) 
    	at org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:308) 
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
    	at java.lang.reflect.Method.invoke(Unknown Source) 
    	at com.servoy.j2db.Za.Za.Zf.invoke(Zf.java:15) 
    	at $Proxy1.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.Zu.performUpdates(Zu.java:933) 
    	at com.servoy.j2db.dataprocessing.EditRecordList.stopEditing(EditRecordList.java:464) 
    	at com.servoy.j2db.dataprocessing.EditRecordList.stopEditing(EditRecordList.java:165) 
    	at com.servoy.j2db.smart.dataui.DataRenderer$1.mouseReleased(DataRenderer.java:112) 
    	at java.awt.Component.processMouseEvent(Unknown Source) 
    	at javax.swing.JComponent.processMouseEvent(Unknown Source) 
    	at java.awt.Component.processEvent(Unknown Source) 
    	at java.awt.Container.processEvent(Unknown Source) 
    	at java.awt.Component.dispatchEventImpl(Unknown Source) 
    	at java.awt.Container.dispatchEventImpl(Unknown Source) 
    	at java.awt.Component.dispatchEvent(Unknown Source) 
    	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) 
    	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) 
    	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) 
    	at java.awt.Container.dispatchEventImpl(Unknown Source) 
    	at java.awt.Window.dispatchEventImpl(Unknown Source) 
    	at java.awt.Component.dispatchEvent(Unknown Source) 
    	at java.awt.EventQueue.dispatchEvent(Unknown Source) 
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) 
    	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) 
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) 
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source) 
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source) 
    	at java.awt.EventDispatchThread.run(Unknown Source)

We’re using Servoy 5.2.1 and Postgres 8.4. Any help is appreciated.

Hi Nicholas,

The error means that your primary key column already holds the value you try to insert as PK.
What do you see as sequence type in the view of this table in servoy ? Dbidentity or Servoy Sequence or something else ?

The sequence is set to DB Identity. I haven’t changed anything with this table so I’m not sure why it’s telling me that the value already exists. The last record in the table has a pk of 193. Is there a way for me to set the sequence to pick up at 194?

Hi Nicholas,

You can edit the database sequence via the DBA tool PgAdmin. Just see what sequence name it uses on the table (see default value of the PK column) and edit that sequence.

Hi Robert,

The default value for the pk in my buttons table is nextval(‘buttons_buttonsid_seq’::regclass). This may be a stupid question, but how do I set the sequence to start at 194?

Thanks.

Hi Nicholas,

nextval(‘buttons_buttonsid_seq’::regclass) means the sequence name is “buttons_buttonsid_seq”.
When you connect PgAdmin to your PostgreSQL server you see the object tree on the left. Just expand the node of your database and you will see the following:[attachment=1]objecttree.png[/attachment]

Open the sequences node here and you will see the buttons_buttonsid_seq sequence in the list. Right click on it to edit it.
Then you get the following dialog:[attachment=0]sequence_edit.png[/attachment]
Here you set the current value field to 194.
Hit the OK button and you are done.

Another option would be to use the commandline editor (psql) and use the following SQL:

ALTER SEQUENCE buttons_buttonsid_seq RESTART WITH 194;

See http://www.postgresql.org/docs/9.0/stat … uence.html for more on this command.

Hope this helps.

Robert again to save the day!

Thanks!