Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Manipulate confluence table by Java API

hongchao song October 29, 2017

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.

 

5 answers

2 votes
Gregor Kasmann_Actonic
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 30, 2017

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();
    }
1 vote
Gregor Kasmann_Actonic
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 1, 2017

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"));
0 votes
KC Integrations August 15, 2019

Did anyone resolve this issue? I'm having the same problem was random pages. Not sure the source of the error?

0 votes
Sean Sun November 7, 2018

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

0 votes
hongchao song October 30, 2017

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

Gregor Kasmann_Actonic
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 30, 2017

In which module do you use it?

Macro? XWork? Something else?

hongchao song October 30, 2017

job-config module.

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

hongchao song November 1, 2017

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?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events