diff --git a/activemq-core/src/main/java/org/apache/activemq/store/jdbc/JDBCPersistenceAdapter.java b/activemq-core/src/main/java/org/apache/activemq/store/jdbc/JDBCPersistenceAdapter.java index 25ea7522b4..191abca581 100755 --- a/activemq-core/src/main/java/org/apache/activemq/store/jdbc/JDBCPersistenceAdapter.java +++ b/activemq-core/src/main/java/org/apache/activemq/store/jdbc/JDBCPersistenceAdapter.java @@ -229,8 +229,13 @@ public class JDBCPersistenceAdapter extends DataSourceSupport implements Persist sequenceGenerator.setLastSequenceId(seq); long brokerSeq = 0; if (seq != 0) { - Message last = (Message)wireFormat.unmarshal(new ByteSequence(getAdapter().doGetMessageById(c, seq))); - brokerSeq = last.getMessageId().getBrokerSequenceId(); + byte[] msg = getAdapter().doGetMessageById(c, seq); + if (msg != null) { + Message last = (Message)wireFormat.unmarshal(new ByteSequence(msg)); + brokerSeq = last.getMessageId().getBrokerSequenceId(); + } else { + LOG.warn("Broker sequence id wasn't recovered properly, possible duplicates!"); + } } return brokerSeq; } catch (SQLException e) { diff --git a/activemq-core/src/main/java/org/apache/activemq/store/jdbc/Statements.java b/activemq-core/src/main/java/org/apache/activemq/store/jdbc/Statements.java index cd9ca8d76a..e61139f200 100755 --- a/activemq-core/src/main/java/org/apache/activemq/store/jdbc/Statements.java +++ b/activemq-core/src/main/java/org/apache/activemq/store/jdbc/Statements.java @@ -309,7 +309,7 @@ public class Statements { public String getDeleteOldMessagesStatement() { if (deleteOldMessagesStatement == null) { deleteOldMessagesStatement = "DELETE FROM " + getFullMessageTableName() - + " WHERE ( EXPIRATION<>0 AND EXPIRATION0 AND EXPIRATION