java.sql.SQLException

If you like a tip written by other Samebug users, mark is as helpful! Marks help our algorithm provide you better solutions and also help other users.
tip

Check if you're not creating unused SQL entities, as it might cause this exception.


rafaelrafael

You have a different solution? A short tip here would help you and many other users who saw this issue last week.

  • GitHub comment 253#242234204
    via GitHub by cimba007
    ,
  • GitHub comment 241#239619972
    via GitHub by yd1234
    ,
  • constraint primary index
    via GitHub by cimba007
    ,
    • java.sql.SQLException: Unable to run insert stmt on object MetricsDoubleTypeDevice(sensorVariable=SensorVariable(id=2, sensor=Sensor(id=2, sensorId=0, type=S_MOTION, name=, lastSeen=1472079238564, node=Node(id=2, eui=20, gatewayTable=GatewayTable(id=1, enabled=true, name=mosquitto, networkType=MY_SENSORS, timestamp=1472065324018, state=UP, statusMessage=Connected Successfully, statusSince=1472078288689, type=MQTT, properties={p=, u=, bh=tcp://localhost:1883, tp=mygateway-in, cid=mycontroller_mqtt_client, ts=mygateway-out}), name=MicrowaveTest, version=Aug 25 2016 | 00:52:22, type=S_ARDUINO_NODE, libVersion=2.0.0, batteryLevel=null, eraseConfig=null, firmware=null, state=UP, lastSeen=1472079238406, rssi=2|2|0|2, properties={}, parentNodeEui=0, registrationState=REGISTERED), room=null, variableTypes=[Variable 1, Variable 2]), variableType=V_VAR1, metricType=DOUBLE, timestamp=1472079239476, value=3.41, previousValue=3.4, unitType=U_NONE, readOnly=false, offset=0.0, priority=100, graphProperties={color=#ff7f0e, interpolate=linear, subType=line, useGlobal=true, type=lineChart}), timestamp=1472079239476, samples=1, min=3.41, max=3.41, avg=3.41, aggregationType=RAW, timestampFrom=null, timestampTo=null): INSERT INTO `metrics_double_type_device` (`sensorVariableId` ,`timestamp` ,`samples` ,`min` ,`max` ,`avg` ,`aggregationType` ) VALUES (?,?,?,?,?,?,?) at com.j256.ormlite.misc.SqlExceptionUtil.create(SqlExceptionUtil.java:22) at com.j256.ormlite.stmt.mapped.MappedCreate.insert(MappedCreate.java:135) at com.j256.ormlite.stmt.StatementExecutor.create(StatementExecutor.java:450) at com.j256.ormlite.dao.BaseDaoImpl.create(BaseDaoImpl.java:310) at org.mycontroller.standalone.db.dao.BaseAbstractDaoImpl.create(BaseAbstractDaoImpl.java:184) at org.mycontroller.standalone.message.McMessageEngine.recordSetTypeData(McMessageEngine.java:847) at org.mycontroller.standalone.message.McMessageEngine.execute(McMessageEngine.java:116) at org.mycontroller.standalone.message.McMessageEngine.run(McMessageEngine.java:973) at java.lang.Thread.run(Thread.java:745) Caused by: org.h2.jdbc.JdbcSQLException: Unique index or primary key violation: "CONSTRAINT_INDEX_4B ON PUBLIC.METRICS_DOUBLE_TYPE_DEVICE(SENSORVARIABLEID, TIMESTAMP, AGGREGATIONTYPE) VALUES ( /* key:63641 */ 2, 1472079239476, null, null, null, null, 0)"; SQL statement: INSERT INTO `metrics_double_type_device` (`sensorVariableId` ,`timestamp` ,`samples` ,`min` ,`max` ,`avg` ,`aggregationType` ) VALUES (?,?,?,?,?,?,?) [23505-176] at org.h2.message.DbException.getJdbcSQLException(DbException.java:344) at org.h2.message.DbException.get(DbException.java:178) at org.h2.message.DbException.get(DbException.java:154) at org.h2.index.BaseIndex.getDuplicateKeyException(BaseIndex.java:103) at org.h2.index.PageBtree.find(PageBtree.java:121) at org.h2.index.PageBtreeLeaf.addRow(PageBtreeLeaf.java:151) at org.h2.index.PageBtreeLeaf.addRowTry(PageBtreeLeaf.java:104) at org.h2.index.PageBtreeNode.addRowTry(PageBtreeNode.java:206) at org.h2.index.PageBtreeNode.addRowTry(PageBtreeNode.java:206) at org.h2.index.PageBtreeIndex.addRow(PageBtreeIndex.java:97) at org.h2.index.PageBtreeIndex.add(PageBtreeIndex.java:88) at org.h2.table.RegularTable.addRow(RegularTable.java:120) at org.h2.command.dml.Insert.insertRows(Insert.java:157) at org.h2.command.dml.Insert.update(Insert.java:115) at org.h2.command.CommandContainer.update(CommandContainer.java:79) at org.h2.command.Command.executeUpdate(Command.java:254) at org.h2.jdbc.JdbcPreparedStatement.executeUpdateInternal(JdbcPreparedStatement.java:158) at org.h2.jdbc.JdbcPreparedStatement.executeUpdate(JdbcPreparedStatement.java:144) at com.j256.ormlite.jdbc.JdbcDatabaseConnection.insert(JdbcDatabaseConnection.java:170) at com.j256.ormlite.stmt.mapped.MappedCreate.insert(MappedCreate.java:91) ... 7 more

    Users with the same issue

    tvrmsmithtvrmsmith
    23 times, last one,
    Andreas HäberAndreas Häber
    1 times, last one,
    Victor_ITVictor_IT
    3 times, last one,
    batwalrus76batwalrus76
    3 times, last one,
    andyglickandyglick
    4 times, last one,
    143 more bugmates