[GIS] How to edit a given version of geodatabase

arcgis-serverarcobjectsesri-geodatabasejavaversioning

I have a versioned geodatabase. Any of that versions are used only by one user. So then user called "XXX" has a version called "XXX". So then now I want to make a changes on given version, but when I create a code like that:

IWorkspaceEdit edit = null;
    try {
        edit = new IWorkspaceEditProxy(findVersion(getVersionedWorkspace(), "myVersion"));
        edit.startEditing(true);
        edit.startEditOperation();
        IFeatureWorkspace featureWorkspace = new IFeatureWorkspaceProxy(getWorkspace());
        ITable iTable = featureWorkspace.openTable("MyTable");
        IRow iRow = iTable.getRow(56);
        StringBuilder builder = new StringBuilder();
        iRow.setValue(21, "test2");
        iRow.store();
        edit.stopEditOperation();
        edit.stopEditing(true);
    } catch (IOException e) {
        e.printStackTrace();
    }

I get an exception:

AutomationException: 0x80041354 – Syntax error in 'Microsoft VBScript compilation error'

When I call this method again a get an information like I should use an edit session

Objects in this object class cannot be updated outside of an edit session.

but how you can see on above code, I start and stop editing and edit operation.

Anyone can give me any hint for that. I also using an IFeatureWorkspace.update method, but I get an information about problem with edit session. I'm not sure what I'm doing wrong, because I can access to database and get rows, but I can't edit them. I am using a JAVA as programming language.

When I change my code into:

IWorkspace iWorkspace = ArcGISServerHelper.getInstance().getWorkspace();
IWorkspaceEdit edit = null;
try { 

    IVersionedWorkspace iVersionedWorkspace = new IVersionedWorkspaceProxy(iWorkspace);
    iWorkspace = new IWorkspaceProxy(iVersionedWorkspace.findVersion("myVersion"));

    edit = new IWorkspaceEditProxy(iVersionedWorkspace.findVersion("myVersion"));
    IFeatureWorkspace featureWorkspace = new IFeatureWorkspaceProxy(iWorkspace);
    ITable iTable = featureWorkspace.openTable("MyTable");
    edit.startEditing(true);
    edit.startEditOperation();

I get an exception:

AutomationException: 0x80004005 – The XML being loaded could not be parsed. [physical name: OWNER.ANNO_TABLE] in 'ESRI GeoDatabase'

Best Answer

Why are you doing this

IFeatureWorkspace featureWorkspace = new IFeatureWorkspaceProxy(getWorkspace());

when you already have the workspace in the "edit" object? My spidy senses are telling me that the workspace returned by getWorkspace() is not the same as the one that you get from

edit = new IWorkspaceEditProxy(findVersion(getVersionedWorkspace(), "myVersion"));

so your StartEditing call and the StartEditOperation have been on a different Version altogether.

Instead, to get the featureWorkspace do

IFeatureWorkspace featureWorkspace = edit as IFeatureWorkspace;