Hello everybody.
I am developing a plugin for Confluence Server, which among other things is responsible of generating pages when a REST API is hit.
In my page generation manager I create a new page this way:
// the PageManager was injected with Spring.
Page myPage = pageManager.getPage(space.getKey(), "My Page");
if (null == myPage)
{
myPage = new Page();
myPage.setTitle("My Page");
myPage.setSpace(space);
myPage.setBodyAsString("<xml>");
myPage.addPermission(ContentPermission.createGroupPermission(ContentPermission.EDIT_PERMISSION, "confluence-users"));
space.getHomePage().addChild(myPage);
// not sure if I have to set the parent/child relationship on both objects, to err on the safe side I do both.
myPage.setParentPage(space.getHomePage());
// saveContext was created with a (true, true, true) builder)
pageManager.saveContentEntity(myPage, saveContext);
}
When the saveContentEntity method is hit, a DuplicateKeyException is thrown:
"A different object with the same identifier value was already associated with the session : [com.atlassian.confluence.spaces.Space#1376257]"
With Cause:
org.hibernate.NonUniqueObjectException: A different object with the same identifier value was already associated with the session : [com.atlassian.confluence.spaces.Space#1376257]
I had the "My Page" page set up under the space homepage, but in order to test automatic creation I deleted it and purged it from the space bin. I looked around and could not find anything that pointed out I was doing something wrong.
What am I missing?
Thank you in advance.