How to change the version number from java?

Hello!
How can I change the version number of a document?
In fact, I would like to get the version and change its number to another one.
Or, as an option, delete the version and add a new one with the required number.

Hello. You cannot and shouldn’t change it. The versioning scheme is managed by XWiki.

What’s your real need (i.e. why do you want to change the version numbers)?

Thanks

I am importing data from another system where there are versions. And I wanted the versions to match each other.
In general, I can create a separate object in which to store the version comparison.
Thanks for your answer!

You can force the version you want to have (provided it follow the format <x>.<y>) in a new history entry when you save the document. That’s what importers (like the Confluence one) usually do.

2 Likes

There’s also another solution but it’s quite involved, it means re-implementing the versioning store.

EDIT: I don’t think it’s ever been done :slight_smile: so it might not even work (there might ties to the XWiki versioning scheme).

If you only need to set versions on first time import, then Thomas’s solution is the best. Then the impored docs will follow xwiki’s versioning scheme afterwars for any subsequent modifications.

1 Like

Could you please point me to a code example?
Or a link where to read it.
This option is quite suitable.
Thank you

It depends a lot on how you are exactly doing your import:

2 Likes

Thank you tmortagne!
It works.