question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ERROR log: Unique index or primary key violation

See original GitHub issue

I have this error in logs :

2016-08-24 17:32:15,783 ERROR [Thread-930275] [org.mycontroller.standalone.db.dao.BaseAbstractDaoImpl:187] unable to add new item:[MetricsBinaryTypeDevice(sensorVariable=SensorVariable(id=7, sensor=Sensor(id=8, sensorId=4, type=S_BINARY, name=Status salon, lastSeen=1472052735701, node=Node(id=4, eui=2, gatewayTable=GatewayTable(id=1, enabled=true, name=g1, networkType=MY_SENSORS, timestamp=null, state=UP, statusMessage=Connected Successfully, statusSince=1471813237223, type=SERIAL, properties={br=115200, rdr=pi4j, rf=120, dr=Auto, pn=/dev/ttyUSB0}), name=Thermostat, version=1.1, type=S_ARDUINO_REPEATER_NODE, libVersion=2.0.0, batteryLevel=null, eraseConfig=null, firmware=null, state=UP, lastSeen=1472052735707, rssi=null, properties={}, parentNodeEui=null, registrationState=REGISTERED), room=null, variableTypes=[Status]), variableType=V_STATUS, metricType=BINARY, timestamp=1472052735738, value=0, previousValue=0, unitType=U_NONE, readOnly=false, offset=0.0, priority=100, graphProperties={color=#ff7f0e, interpolate=linear, subType=line, useGlobal=true, type=lineChart}), timestamp=1472052735738, state=false, timestampFrom=null, timestampTo=null)]
java.sql.SQLException: Unable to run insert stmt on object MetricsBinaryTypeDevice(sensorVariable=SensorVariable(id=7, sensor=Sensor(id=8, sensorId=4, type=S_BINARY, name=Status salon, lastSeen=1472052735701, node=Node(id=4, eui=2, gatewayTable=GatewayTable(id=1, enabled=true, name=g1, networkType=MY_SENSORS, timestamp=null, state=UP, statusMessage=Connected Successfully, statusSince=1471813237223, type=SERIAL, properties={br=115200, rdr=pi4j, rf=120, dr=Auto, pn=/dev/ttyUSB0}), name=Thermostat, version=1.1, type=S_ARDUINO_REPEATER_NODE, libVersion=2.0.0, batteryLevel=null, eraseConfig=null, firmware=null, state=UP, lastSeen=1472052735707, rssi=null, properties={}, parentNodeEui=null, registrationState=REGISTERED), room=null, variableTypes=[Status]), variableType=V_STATUS, metricType=BINARY, timestamp=1472052735738, value=0, previousValue=0, unitType=U_NONE, readOnly=false, offset=0.0, priority=100, graphProperties={color=#ff7f0e, interpolate=linear, subType=line, useGlobal=true, type=lineChart}), timestamp=1472052735738, state=false, timestampFrom=null, timestampTo=null): INSERT INTO `metrics_binary_type_device` (`sensorVariableId` ,`timestamp` ,`state` ) VALUES (?,?,?)
    at com.j256.ormlite.misc.SqlExceptionUtil.create(SqlExceptionUtil.java:22) ~[mycontroller-dist-standalone-0.0.3.Alpha2-single.jar:0.0.3.Alpha2]
    at com.j256.ormlite.stmt.mapped.MappedCreate.insert(MappedCreate.java:135) ~[mycontroller-dist-standalone-0.0.3.Alpha2-single.jar:0.0.3.Alpha2]
    at com.j256.ormlite.stmt.StatementExecutor.create(StatementExecutor.java:450) ~[mycontroller-dist-standalone-0.0.3.Alpha2-single.jar:0.0.3.Alpha2]
    at com.j256.ormlite.dao.BaseDaoImpl.create(BaseDaoImpl.java:310) ~[mycontroller-dist-standalone-0.0.3.Alpha2-single.jar:0.0.3.Alpha2]
    at org.mycontroller.standalone.db.dao.BaseAbstractDaoImpl.create(BaseAbstractDaoImpl.java:184) ~[mycontroller-dist-standalone-0.0.3.Alpha2-single.jar:0.0.3.Alpha2]
    at org.mycontroller.standalone.message.McMessageEngine.recordSetTypeData(McMessageEngine.java:848) [mycontroller-dist-standalone-0.0.3.Alpha2-single.jar:0.0.3.Alpha2]
    at org.mycontroller.standalone.message.McMessageEngine.execute(McMessageEngine.java:116) [mycontroller-dist-standalone-0.0.3.Alpha2-single.jar:0.0.3.Alpha2]
    at org.mycontroller.standalone.message.McMessageEngine.run(McMessageEngine.java:962) [mycontroller-dist-standalone-0.0.3.Alpha2-single.jar:0.0.3.Alpha2]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_65]
Caused by: org.h2.jdbc.JdbcSQLException: Unique index or primary key violation: "CONSTRAINT_INDEX_47 ON PUBLIC.METRICS_BINARY_TYPE_DEVICE(SENSORVARIABLEID, TIMESTAMP) VALUES ( /* key:26871 */ 7, 1472052735738, null)"; SQL statement:
INSERT INTO `metrics_binary_type_device` (`sensorVariableId` ,`timestamp` ,`state` ) VALUES (?,?,?) [23505-176]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:344) ~[mycontroller-dist-standalone-0.0.3.Alpha2-single.jar:0.0.3.Alpha2]
    at org.h2.message.DbException.get(DbException.java:178) ~[mycontroller-dist-standalone-0.0.3.Alpha2-single.jar:0.0.3.Alpha2]
    at org.h2.message.DbException.get(DbException.java:154) ~[mycontroller-dist-standalone-0.0.3.Alpha2-single.jar:0.0.3.Alpha2]
    at org.h2.index.BaseIndex.getDuplicateKeyException(BaseIndex.java:103) ~[mycontroller-dist-standalone-0.0.3.Alpha2-single.jar:0.0.3.Alpha2]
    at org.h2.index.PageBtree.find(PageBtree.java:121) ~[mycontroller-dist-standalone-0.0.3.Alpha2-single.jar:0.0.3.Alpha2]
    at org.h2.index.PageBtreeLeaf.addRow(PageBtreeLeaf.java:151) ~[mycontroller-dist-standalone-0.0.3.Alpha2-single.jar:0.0.3.Alpha2]
    at org.h2.index.PageBtreeLeaf.addRowTry(PageBtreeLeaf.java:104) ~[mycontroller-dist-standalone-0.0.3.Alpha2-single.jar:0.0.3.Alpha2]
    at org.h2.index.PageBtreeNode.addRowTry(PageBtreeNode.java:206) ~[mycontroller-dist-standalone-0.0.3.Alpha2-single.jar:0.0.3.Alpha2]
    at org.h2.index.PageBtreeNode.addRowTry(PageBtreeNode.java:206) ~[mycontroller-dist-standalone-0.0.3.Alpha2-single.jar:0.0.3.Alpha2]
    at org.h2.index.PageBtreeIndex.addRow(PageBtreeIndex.java:97) ~[mycontroller-dist-standalone-0.0.3.Alpha2-single.jar:0.0.3.Alpha2]
    at org.h2.index.PageBtreeIndex.add(PageBtreeIndex.java:88) ~[mycontroller-dist-standalone-0.0.3.Alpha2-single.jar:0.0.3.Alpha2]
    at org.h2.table.RegularTable.addRow(RegularTable.java:120) ~[mycontroller-dist-standalone-0.0.3.Alpha2-single.jar:0.0.3.Alpha2]
    at org.h2.command.dml.Insert.insertRows(Insert.java:157) ~[mycontroller-dist-standalone-0.0.3.Alpha2-single.jar:0.0.3.Alpha2]
    at org.h2.command.dml.Insert.update(Insert.java:115) ~[mycontroller-dist-standalone-0.0.3.Alpha2-single.jar:0.0.3.Alpha2]
    at org.h2.command.CommandContainer.update(CommandContainer.java:79) ~[mycontroller-dist-standalone-0.0.3.Alpha2-single.jar:0.0.3.Alpha2]
    at org.h2.command.Command.executeUpdate(Command.java:254) ~[mycontroller-dist-standalone-0.0.3.Alpha2-single.jar:0.0.3.Alpha2]
    at org.h2.jdbc.JdbcPreparedStatement.executeUpdateInternal(JdbcPreparedStatement.java:158) ~[mycontroller-dist-standalone-0.0.3.Alpha2-single.jar:0.0.3.Alpha2]
    at org.h2.jdbc.JdbcPreparedStatement.executeUpdate(JdbcPreparedStatement.java:144) ~[mycontroller-dist-standalone-0.0.3.Alpha2-single.jar:0.0.3.Alpha2]
    at com.j256.ormlite.jdbc.JdbcDatabaseConnection.insert(JdbcDatabaseConnection.java:170) ~[mycontroller-dist-standalone-0.0.3.Alpha2-single.jar:0.0.3.Alpha2]
    at com.j256.ormlite.stmt.mapped.MappedCreate.insert(MappedCreate.java:91) ~[mycontroller-dist-standalone-0.0.3.Alpha2-single.jar:0.0.3.Alpha2]
    ... 7 common frames omitted

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
cimba007commented, Aug 24, 2016

Hello gbrd, can u provide a full log file or copy the content of “~/mycontroller/logs/mycontroller.log” to a site like http://pastebin.com/

To not make the data public on pastebin select “Paste Exposure: Unlisted”

0reactions
jkandasacommented, Oct 27, 2016

@gbrd I have included timestamp on message which is on queue. I hope this issue will not occur again.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unique index or primary key violation - SQL statement
To resolve this issue pass primary key column value as unique and not NULL. just simply add NOT NULL UNIQUE at the end...
Read more >
Why am I getting a primary/unique key violation? - SQL Studies
This is by far the most common cause of a unique/primary key error that I see. A row exists in the table and...
Read more >
unique index or primary key violation | Facing Issues On IT
To resolve this issue pass primary key column value as unique and not NULL. You would like to see. Follow below link to...
Read more >
"Unique index or primary key violation" for unknown constraint
Hi, I am using h2 version 1.2.137 with hibernate 3.5.1-Final and I am getting a strange Unique index exception: Unique index or primary...
Read more >
H2 v1.4.197 fails to open an existing database with the error ...
H2 v1.4.197 fails to open an existing database with the error [Unique index or primary key violation: "PRIMARY KEY ON """".PAGE_INDEX"] ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found