[ 
https://issues.apache.org/jira/browse/JENA-1207?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15363393#comment-15363393
 ] 

Andy Seaborne commented on JENA-1207:
-------------------------------------

Use
{noformat}
RDFDatatype datatype = XSDDatatype.XSDdecimal ;
{noformat}
rather than {{new XSDDatatype("decimal");}}.

TDB does not recognize the type to inline properly in all places; actually 
because it avoids parsing strings in one place but instead checks the type for 
validity. Creating the literal with an ad-hoc type (the constructor is public 
only because it is called from another package, not as the public API) causes 
confusion as type names get written out and read back in, so loosing the 
association with your ad-hoc created version of {{xsd:decimal}}.


> Adding Decimal Typed Literal Results in TDBException on Dataset Commit
> ----------------------------------------------------------------------
>
>                 Key: JENA-1207
>                 URL: https://issues.apache.org/jira/browse/JENA-1207
>             Project: Apache Jena
>          Issue Type: Bug
>          Components: TDB
>    Affects Versions: Jena 3.1.0
>         Environment: Mac OSX
>            Reporter: Kai He
>         Attachments: add-decimal-literals.zip
>
>
> When adding a statement of the form 
> [http://www.myhost.com/mysubject, http://www.myhost.com/mypredicate, 
> "2.2"^^http://www.w3.org/2001/XMLSchema#decimal]
> using the following snippet
> {code:java}
> import java.util.ArrayList;
> import java.util.List;
> import org.apache.jena.datatypes.RDFDatatype;
> import org.apache.jena.datatypes.xsd.XSDDatatype;
> import org.apache.jena.query.Dataset;
> import org.apache.jena.query.ReadWrite;
> import org.apache.jena.rdf.model.Model;
> import org.apache.jena.rdf.model.Property;
> import org.apache.jena.rdf.model.RDFNode;
> import org.apache.jena.rdf.model.Resource;
> import org.apache.jena.rdf.model.ResourceFactory;
> import org.apache.jena.rdf.model.Statement;
> import org.apache.jena.tdb.TDBFactory;
> public class DecimalExample {
>       
>       public static void main(String[] args) {
>               String tdbPath = "absolute/path/here";
>               Dataset dataset = TDBFactory.createDataset( tdbPath );
>               
>               Resource subject = 
> ResourceFactory.createResource("http://www.myhost.com/mysubject";);
>               Property predicate = 
> ResourceFactory.createProperty("http://www.myhost.com/mypredicate";);
>               RDFDatatype datatype = new XSDDatatype("decimal");
>               RDFNode object = ResourceFactory.createTypedLiteral("2.2", 
> datatype);
>               
>               List<Statement> statements = new ArrayList<Statement>();
>               statements.add( ResourceFactory.createStatement(subject, 
> predicate, object) );
>               
>               dataset.begin(ReadWrite.WRITE);
>               try {
>                       
>                       Model model = dataset.getDefaultModel();
>                       
>                       model.add(statements);
>                       dataset.commit();
>                       
>               } catch (Exception e) {
>                       
>                       e.printStackTrace();
>                       dataset.abort();
>                       
>               } finally {
>                       dataset.end();
>               }
>               
>       }
> }
> {code}
> A TDBException is thrown. The stack trace shows the following:
> {code:java}
> SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
> SLF4J: Defaulting to no-operation (NOP) logger implementation
> SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further 
> details.
> Different ids for "2.2"^^http://www.w3.org/2001/XMLSchema#decimal: allocated: 
> expected [0000000000000000], got [0201000000000016]
> >>>>>>>>>>
> label = nodes
> txn = Transaction: 1 : Mode=WRITE : State=PREPARING : 
> /Users/kaihe/Documents/experimental/tdb/
> offset = 0
> journalStartOffset = 0
> journal = nodes
> org.apache.jena.tdb.transaction.TDBTransactionException: Abort during prepare 
> - transaction did not commit
>       at 
> org.apache.jena.tdb.transaction.Transaction.commit(Transaction.java:123)
>       at 
> org.apache.jena.tdb.transaction.DatasetGraphTxn.commit(DatasetGraphTxn.java:54)
>       at 
> org.apache.jena.tdb.transaction.DatasetGraphTransaction._commit(DatasetGraphTransaction.java:146)
>       at 
> org.apache.jena.sparql.core.DatasetGraphTrackActive.commit(DatasetGraphTrackActive.java:46)
>       at org.apache.jena.sparql.core.DatasetImpl.commit(DatasetImpl.java:123)
>       at DecimalExample.main(DecimalExample.java:37)
> Caused by: org.apache.jena.tdb.TDBException: Different ids for 
> "2.2"^^http://www.w3.org/2001/XMLSchema#decimal: allocated: expected 
> [0000000000000000], got [0201000000000016]
>       at 
> org.apache.jena.tdb.transaction.NodeTableTrans.inconsistent(NodeTableTrans.java:232)
>       at 
> org.apache.jena.tdb.transaction.NodeTableTrans.append(NodeTableTrans.java:220)
>       at 
> org.apache.jena.tdb.transaction.NodeTableTrans.writeNodeJournal(NodeTableTrans.java:317)
>       at 
> org.apache.jena.tdb.transaction.NodeTableTrans.commitPrepare(NodeTableTrans.java:289)
>       at 
> org.apache.jena.tdb.transaction.Transaction.prepare(Transaction.java:172)
>       at 
> org.apache.jena.tdb.transaction.Transaction.commit(Transaction.java:108)
>       ... 5 more
> {code}
> The problem goes away when adding statements with integer values like 
> [http://www.myhost.com/mysubject, http://www.myhost.com/mypredicate, 
> "2"^^http://www.w3.org/2001/XMLSchema#integer] 



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to