尝试提交事务时,Jena的TDB数据集得到了TDBTransactionException

时间:2018-04-22 09:16:42

标签: graph sparql rdf jena

这就是我写的:

public static void main(String[] args) {
    Dataset dataset = TDBFactory.createDataset("/tmp/someThings");
    dataset.begin(ReadWrite.WRITE);
    Model model = dataset.getDefaultModel();
    model.setNsPrefix("kg", "http://sankuai.com/kg");
    Resource resource = model.createResource("http://sankuai.com/kg/jena");
    resource.addProperty(model.createProperty("kg", "language"), "SPARQL");
    dataset.commit();
    System.out.println(model);
}

但是给我一些输出,它显示错误:

Exception in thread "main" org.apache.jena.tdb.transaction.TDBTransactionException: Not in a transaction

我做的事情有错吗?

1 个答案:

答案 0 :(得分:2)

问题在于我检索模型时:

System.out.println(model);

它必须包含在交易中,我不是......