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

This widget could not be displayed.

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();
    }
This widget could not be displayed.

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?

This widget could not be displayed.

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
Community showcase
Posted Sep 17, 2018 in Confluence

Why start from scratch? Introducing four new templates for Confluence Cloud

Hi my Community friends!  For those who don't know me, I'm a product marketer on the Confluence Cloud team - nice to meet you! For those of you who do, you know that I've been all up in your Co...

601 views 8 6
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