Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8568979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:13:45+00:00 2026-06-11T18:13:45+00:00

I want to delete and insert triples from a sesame repository using SPARQL queries,

  • 0

I want to delete and insert triples from a sesame repository using SPARQL queries, and I want to execute both operations as a single transaction.

  1. DELETE
  2. INSERT

If an exception is thrown during the transaction, rollback is executed… but it seems not to work.
The problem is that, if an exception is thrown during the insert query, the rollback is executed, but the previously deleted triples are not recovered (Why?).

Here you have some code:

I have a class called OwlimConnector which wraps the repository connection and provides some methods to make SPARQL Queries.
In the constructor of this class, I set up the connection and I set the autocommit to false:

RemoteRepositoryManager repos_manager = RemoteRepositoryManager.getInstance(SERVER_URL, USER, PASSWORD);
repos_manager.initialize();
Repository ssr = repos_manager.getRepository(REPOSITORY);
rconn = ssr.getConnection();
rconn.setAutoCommit(false);

In OwlimConnector there is a method called executeUpdate:

public void executeUpdate(String queryString) throws RepositoryException,                MalformedQueryException, UpdateExecutionException
{
  Update up = rconn.prepareUpdate(QueryLanguage.SPARQL, queryPrefixString + queryString);
  up.execute();
}

and these methods among others:

public void commit(){
rconn.commit();
}

public void rollback() {        
rconn.rollback();
}

public void close(){
rconn.close();
}

On the other hand, I have a web service “updateUserGroup” wich uses the previous OwlimConnector and a data access object called UserGroupDAO:

@PUT
@Consumes(MediaType.APPLICATION_XML)
public Response updateUserGroup(UserGroup ug) {

try {
    oc = new OwlimConnector();
} catch (OwlimInstantiationException e) {
    return ResponseFactory.getError(e.getErrorMessage());
}

try {
    UserGroupDAO ugdao = new UserGroupDAO(oc);
    ugdao.delete(ug.getUri());
    ugdao.add(ug);
    oc.commit();
    oc.close();
    return ResponseFactory.getOK();
} catch (MandatoryFieldException e) {
    oc.rollback();
    oc.close();
    return ResponseFactory.getError(e.getErrorMessage());
} catch (NotExistingResourceException e) {
    oc.rollback();
    oc.close();
    return ResponseFactory.getError(e.getErrorMessage());
} catch (Exception e) {
    oc.rollback();
    oc.close();
    return ResponseFactory.getError(new GenericException(e).getErrorMessage());
}

}

1 What ugdao.delete(ug.getUri()) does is to call the OwlimConnector method executeUpdate:

oc.executeUpdate("DELETE { " + usergroup + " ?p ?v . } WHERE { " + usergroup + " ?p ?v . }");

Here the triples are deleted even though there is no commit!

2 What ugdao.add(ug) does is:

To check that ug.getName() is not null or spaces, otherwise the MandatoryFieldException is thrown:

if (ug.getName() == null || ug.getName().equals("")){
throw new MandatoryFieldException("name");
}

Then, the data is inserted:

oc.executeUpdate("INSERT DATA { " + ug.getUri() + " a scmu:UserGroup ; scmu:hasName \"" + ug.getName() + "\" . }");

When ug.getName() is null or spaces the MandatoryFieldException exception is thrown and caught by updateUserGroup. Then the rollback is executed but the deleted triples are not recovered.

I don´t know why this happens. Any Idea?

Thank you very much in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T18:13:46+00:00Added an answer on June 11, 2026 at 6:13 pm

    The solution is much easier than I thought. This is the answer I received from the Ontotext AD in the mailing list:

    “you are using RemoteRepository so each update, is immediately sent to the remote repository at up.execute() and there it is autocommited immediately .

    what you could do is instead of preparing and executing on each delete/add operation in your service to start collecting all individual updates (into a StringBuilder for instance) and on oc.commit() to prepare and execute the whole list of updates at once (and just clear the list on rollback, in case an exception is thrown)

    Your update request can have multiple ‘INSERT DATA’ or ‘DELETE DATA’ updates … “

    And it works! Thank you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to have an 'updateinfo' table in order to record every update/insert/delete operations
i want to build a tree in java. operations such as insert delete update.
I want to delete records from mysql using php the field name: Week Week
I want to insert and delete some chars in the middle of a file.
I want to delete DataRows from a DataTable. The rows to be deleted are
I want to delete an entry from my Database but it says it can't
I want to delete a file into recycle bin. I using this code. SHFILEOPSTRUCT
I want to delete an array index from an array, then reload listView with
I want to delete a number of jobs from a q. The command to
Hi I want to delete selected item from the data base. My code is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.