Hello everyone!
I use Apache Jena version 2.13.0.
I try to add in existing Graph new triple by using SPARQL, and triple didn’t
added, here is the code:
public class TestTransactions {
public static void main(String[] args) {
Dataset dataset = TDBFactory.createDataset();
DatasetGraph datasetGraph = dataset.asDatasetGraph();
Graph graph = datasetGraph.getDefaultGraph();
// Fill graph.
graph.add(
new Triple(
NodeFactory.createURI("http://example/unit13"),
NodeFactory.createURI("http://example/name"),
NodeFactory.createLiteral("Unit 13", "en")
)
);
graph.add(
new Triple(
NodeFactory.createURI("http://example/unit13"),
NodeFactory.createURI("http://example/type"),
NodeFactory.createURI("http://example/robot")
)
);
graph.add(
new Triple(
NodeFactory.createURI("http://example/unit13"),
NodeFactory.createURI("http://example/creationYear"),
NodeFactory.createURI("http://example/2015")
)
);
// Test.
dataset.begin(ReadWrite.WRITE);
UpdateRequest request =
UpdateFactory.create(
"INSERT { ?s <http://example/value> '1' } WHERE { ?s
<http://example/creationYear> <http://example/2015> . }"
);
UpdateAction.execute(request, dataset);
dataset.commit();
dataset.end();
RDFDataMgr.write(System.out, graph, RDFFormat.NTRIPLES);
}
}
If I remove “dataset.begin(ReadWrite.WRITE);”, “dataset.commit();” and
“dataset.end();” triple will be inserted…
Test project on GitHub https://github.com/Hronom/test-jena