Thanks Andy but finally I have found a solution! ...I work on Jena 2.9.2
and TDB 0.9.2
I have included the operations inside a commit operation.
Thus,
Dataset dataset = TDBFactory.createDataset(directory);
dataset.begin(ReadWrite.WRITE);
OntModel model1 = getReasonerModelTest(URI);
dataset.addNamedModel(NS, model1);
dataset.commit();
dataset.end();
dataset.close();
Dataset dataset2 = TDBFactory.createDataset(directory);
dataset2.begin(ReadWrite.WRITE);
OntModel model2 = ModelFactory.createOntologyModel(OntModelSpec.
bla bla...);
model2.write(System.out, "RDF/XML");
...bla bla..
The curious thing, It is in the second commit. I have to declare it in
WRITE mode. It seems that the model.write-operation needs to write in a
certain part of the model. It's strange, isn't?
Well... thanks again
Isaac
El 05/09/12 16:16, Andy Seaborne escribió:
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.
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
--
-----------------------------------------
Dr. Isaac Lera
Dept. Matemàtiques i Informàtica
Ed. Anselm Turmeda, Desp 132
Universitat de les Illes Balears
Palma de Mallorca, Spain, 07122
Telf.: (+34) 971 17 2005
Web: http://acsic.uib.es/isaaclera/
-----------------------------------------