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.

 

3 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"));

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Kesha Thillainayagam
Posted Apr 13, 2018 in Confluence

We want to hear how your non-technical teams are using Confluence!

Hi Community! Kesha (kay-sha) from the Confluence marketing team here! Can you share stories with us on how your non-technical (think Marketing, Sales, HR, legal, etc.) teams are using Confluen...

380 views 21 10
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