org.hibernate.StaleObjectStateException while adding new attachment using attachmentManager.saveAttachment

I have a functionality where in I need to create a page and add an image as attachment to page. Page creation is successful but when i trying to add an attachment to page, I get this exception,

Object of class [com.atlassian.confluence.pages.Page] with identifier [1281335134]: optimistic locking failed; nested exception is org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) : [com.atlassian.confluence.pages.Page#xxxxxxxx

code used to save attachment,
Attachment attachment = new Attachment(file.getName(), “image/png”, file.length(), “”);
attachment.setCreationDate(new Date());
attachment.setLastModificationDate(new Date());
this.attachmentManager.saveAttachment(attachment, null, new FileInputStream(file));

Any solutions how to solve this would be great

Just for Info, the same code is working fine in confluence version 7.4.6 and this error is appearing in 7.13.5