Manipulate confluence table by Java API

Hi guys,

I need to insert rows into table dynamically by Java API but not Rest API.

When I implementing it through saveContentEntity(ContentEntityObject obj, SaveContext saveContext)  or  saveContentEntity(ContentEntityObject obj, ContentEntityObject origObj, SaveContext saveContext) , it throws org.hibernate.HibernateException: Unable to resolve owner of loading collection [[com.atlassian.confluence.core.ContentEntityObject.contentProperties#819205]] for second level caching .

Could somebody please give me some help? or some sample code for manipulating table dynamically  by Java API

Thanks in advance.

 

4 answers

Try this solution:

pageManager.saveNewVersion(targetPage, new PageModification(newPageContent), getDefaultSaveContext());

 

class PageModification implements Modification<Page> {
        private String newBody;

        public PageModification(String newBody) {
            this.newBody = newBody;
        }

        @Override
        public void modify(Page page) {
            page.setBodyAsString(newBody);
            page.setVersionComment("Page uploaded with same templates.");
        }
    } 

 

private SaveContext getDefaultSaveContext() {
        return DefaultSaveContext.builder().suppressNotifications(true).updateLastModifier(true).suppressEvents(false).build();
    }

thanks, but it still throw the same exception,  ::>_<::

In which module do you use it?

Macro? XWork? Something else?

job-config module.

Is it up to module type? Could you please give me more details?

I implementd the same function on the Macro and Job-config module separately, and only Macro module works well.
It seems only Macro module support this approach ,is it correct?

If you execute any user related actions from Job Module, you have to SET some active user or will receive an Exception.

AuthenticatedUserThreadLocal.set(userAccessor.getUserByName("admin"));

hi  hongchao, have you fixed it. I meet the same issue. Could you give me any suggestion on this. Thx!

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Monday in Confluence

Organizing your space just got easier - Page Tree Drag & Drop is here

Hi Community! I’m Elaine, Confluence Product Manager. You may have read my earlier post about page tree in space navigation sidebar. I'm excited to share another improvement that helps you organize ...

68 views 3 2
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you