protected long lockedNextModSeq(MailboxSession session, Mailbox<Long> mailbox) throws MailboxException {
EntityManager manager = null;
try {
manager = factory.createEntityManager();
manager.getTransaction().begin();
JPAMailbox m = manager.find(JPAMailbox.class, mailbox.getMailboxId());
long modSeq = m.consumeModSeq();
manager.persist(m);
manager.getTransaction().commit();
return modSeq;
} catch (PersistenceException e) {
if (manager != null && manager.getTransaction().isActive()) {