2 Replies Latest reply on Oct 6, 2005 5:10 AM by celinemurphy

    Unique constraint violation

    celinemurphy

      Shouldn't there be an order by messageid in this select statement?

      Thanks
      Celine

      SELECT_MESSAGE = SELECT MESSAGEID, MESSAGEBLOB FROM JMS_MESSAGES WHERE MESSAGEID=? AND DESTINATION=?

      public SpyMessage loadFromStorage(MessageReference messageRef) throws JMSException
      {
      if (log.isTraceEnabled())
      log.trace("Loading message from storage " + messageRef);

      TransactionManagerStrategy tms = new TransactionManagerStrategy();
      tms.startTX();
      Connection c = null;
      PreparedStatement stmt = null;
      ResultSet rs = null;
      boolean threadWasInterrupted = Thread.interrupted();
      try
      {
      c = this.getConnection();
      stmt = c.prepareStatement(SELECT_MESSAGE);
      stmt.setLong(1, messageRef.messageId);
      stmt.setString(2, messageRef.getPersistentKey());

      rs = stmt.executeQuery();
      if (rs.next())
      return extractMessage(rs, 2);

      return null;

      }
      catch (IOException e)
      {
      tms.setRollbackOnly();
      throw new SpyJMSException("Could not load message : " + messageRef, e);
      }
      catch (SQLException e)
      {
      tms.setRollbackOnly();
      throw new SpyJMSException("Could not load message : " + messageRef, e);
      }
      finally
      {
      try
      {
      rs.close();
      }
      catch (Throwable ignore)
      {
      }
      try
      {
      stmt.close();
      }
      catch (Throwable ignore)
      {
      }
      try
      {
      c.close();
      }
      catch (Throwable ignore)
      {
      }
      tms.endTX();

      // Restore the interrupted state of the thread
      if( threadWasInterrupted )
      Thread.currentThread().interrupt();
      }
      }

      protected SpyMessage extractMessage(ResultSet rs, int column) throws SQLException, IOException
      {
      long messageid = rs.getLong(1);
      SpyMessage message = null;
      if (blobType == OBJECT_BLOB)
      {
      message = (SpyMessage) rs.getObject(column);
      }
      else if (blobType == BYTES_BLOB)
      {
      byte[] st = rs.getBytes(column);
      ByteArrayInputStream baip = new ByteArrayInputStream(st);
      ObjectInputStream ois = new ObjectInputStream(baip);
      message = SpyMessage.readMessage(ois);
      }
      else if (blobType == BINARYSTREAM_BLOB)
      {
      ObjectInputStream ois = new ObjectInputStream(rs.getBinaryStream(column));
      message = SpyMessage.readMessage(ois);
      }
      else if (blobType == BLOB_BLOB)
      {
      ObjectInputStream ois = new ObjectInputStream(rs.getBlob(column).getBinaryStream());
      message = SpyMessage.readMessage(ois);
      }
      message.header.messageId = messageid; return message;
      }

        • 1. Re: Unique constraint violation
          celinemurphy

          sorry. scrap that....

          • 2. Re: Unique constraint violation
            celinemurphy

            I am just trying to get to the bottom of this error.

            Has anyone encountered it before? The JMS is configured to be non - persistent - the messages are only transferred if the memory starts to get scarce.

            But it seems like there is a bug somewhere - in jboss version 4.0.0 where it is trying to insert a duplicate primary key. But I cannot find it.

            08:13:49: ln6p2034app: IOIEditor: ERR: IOIBrokerBean::sendMessage() - JMS Exception caught sending message : org.jboss.mq.SpyJMSException: Could not store message: 16641774 msg=369111 hard NOT_STORED NON_PERSISTENT queue=TOPIC.jms.topic.IOITopic.ioiEditorAppLogin1123805403413.-2147483648 priority=9 lateClone=false hashCode=22079513; - nested throwable: (java.sql.SQLException: Unique constraint violation: in statement [INSERT INTO JMS_MESSAGES (MESSAGEID, DESTINATION, MESSAGEBLOB, TXID, TXOP) VALUES(?,?,?,?,?)]

            Since I cant find anywhere that does select max(messageid) from the database i presume that the message id and its incrementation is all done in memory.

            protected long nextMessageId()
            {
            if (parameters.lateClone)
            return nextSharedMessageId();

            synchronized (nextMessageIdLock)
            {
            return nextMessageIdCounter++;
            }
            }

            protected void updateNextMessageId(SpyMessage message)
            {
            if (parameters.lateClone)
            {
            updateSharedNextMessageId(message);
            return;
            }

            synchronized (nextMessageIdLock)
            {
            nextMessageIdCounter = Math.max(nextMessageIdCounter, message.header.messageId+1);
            }
            }

            Maybe it has been fixed in a later version of jboss?