You are mixing non-transactional use with transactional use and this
breaks things, your initial insert is in non-transactional mode but then
you start a transaction so some of the changes get lost

You should always stick to one usage model, we strongly recommend
transactional use

Simply moving your dataset.begin(ReadWrite.WRITE); call to before you
start making changes to the graph should resolve your issue

Rob

On 06/08/2015 14:31, "Eugene Tenkaev (Hronom)" <[email protected]> wrote:

>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




Reply via email to