Forget the main part of the first reply - it's simpler than that :-)
On 05/09/12 15:16, Andy Seaborne wrote:
On 05/09/12 14:51, Isaac Lera wrote:
Hi!
I make a simple program to test TDB but I don't reach the starting line.
I attach the code:
*************
Location directory = new Location("data/DB4");
Dataset dataset = TDBFactory.createDataset(directory);
OntModel model1 =
ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_RDFS_INF,
dataset.getNamedModel(NS));
dataset.addNamedModel("hello", model1);
You should use an absolute URI at this point, not a simple string.
dataset.addNamedModel("http://example/hello", model1);
but this isn't the problem because when I tried it I just got "hello" back.
dataset.close();
//the ontology is loaded at model1 perfectly
And now, I try to see if the model was saved.
so this code is run right after the previous code in the same JVM? no
another program run?
If I do that, I do get the same exception.
It's because you have closed the dataset and you are not using transactions.
A raw close really does close the dataset permanently - but
TDBFactory.createDataset returns the cached (now closed) copy. I see is
this is fixable but the dataset implementation being used
non-transactionally is the same as the raw storage and that interacts
with transactions.
Fix: don't call dataset.close()
And ideally put a write transaction around the first part and a read
transaction around the second part.
Andy
Dataset dataset2 = TDBFactory.createDataset(directory);
Iterator<String> listNames = dataset2.listNames();
while (listNames.hasNext()){
String name=listNames.next();
System.out.println(name);
}
I hope to find the word-model "hello" but no...
I obtain the next exception:
Exception in thread "main" java.lang.NullPointerException
at
com.hp.hpl.jena.tdb.store.DatasetGraphTDB.listGraphNodes(DatasetGraphTDB.java:258)
at
com.hp.hpl.jena.tdb.migrate.DatasetGraphTrackActive.listGraphNodes(DatasetGraphTrackActive.java:129)
at
com.hp.hpl.jena.sparql.core.DatasetImpl.listNames(DatasetImpl.java:232)
at ip.testJena.App.main(App.java:52)
What is wrong with that simple example?
Assuming Jena version 2.7.3, then it looks like the database directory
is damaged in some way -- the line of code that corresponds to suggests
that something low level is wrong.
I can't reproduce that here from your code (using the current TDB
development build or Jena 2.7.3).
It is possible that the size of data in named model NS is triggering
things already fixed for restart and recovery issues in 2.7.3.
Could you please try the development build?
https://repository.apache.org/content/groups/snapshots/org/apache/jena/apache-jena/2.7.4-SNAPSHOT/
(latest at the bottom - currently 32)
If that does not fix it, could we have a complete, minimal example that
reproduces the setup?
Andy
Thanks
Isaac