# Differences in handling of BNodes between SNARK and RDF4J APIs

**URL:** <https://community.stardog.com/t/differences-in-handling-of-bnodes-between-snark-and-rdf4j-apis/1529>\
**Category:** Bug\
**Created:** [March 19, 2019, 12:33pm UTC](https://community.stardog.com/t/differences-in-handling-of-bnodes-between-snark-and-rdf4j-apis/1529 "2019-03-19T12:33:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![onto\_rory](https://avatars.discourse-cdn.com/v4/letter/o/c37758/32.png) [@onto\_rory](https://community.stardog.com/u/onto_rory)\
**Post date:** [March 19, 2019, 12:33pm UTC](https://community.stardog.com/t/differences-in-handling-of-bnodes-between-snark-and-rdf4j-apis/1529/1 "2019-03-19T12:33:39Z")

</div>

Hi

Whilst testing Stardog 7 (same behaviour in v6.1.2 as far as I can see), there are some differences in passing through query bindings that are BNodes. If using the SNARK API, it works as expected. If using the RDF4J API layer, then I get no results

When using the data below

```
@prefix : <http://something.com/bnode-test#> .

[] a :Country ;
   :name 'UK' ;
   :currency 'Sterling' ;
   :languages 'English', 'Welsh', 'Gaelic', 'Kernow' .

```

And then using the test code, I'd expect 4 results for each run - but get 0 for the RDF4J version

```
import com.complexible.stardog.api.Connection;
import com.complexible.stardog.api.ConnectionConfiguration;
import com.complexible.stardog.api.SelectQuery;
import com.complexible.stardog.rdf4j.StardogRepository;
import com.complexible.stardog.rdf4j.StardogRepositoryConnection;
import org.eclipse.rdf4j.model.Value;
import org.eclipse.rdf4j.query.BindingSet;
import org.eclipse.rdf4j.query.TupleQuery;
import org.eclipse.rdf4j.query.TupleQueryResult;

public class BNodeTest {

    private static final String GET_COUNTRY =
            "PREFIX : <http://something.com/bnode-test#> " +
                    "select distinct ?c { ?c a :Country ; :name 'UK' }";

    private static final String GET_DETAILS =
            "PREFIX : <http://something.com/bnode-test#> " +
            "select distinct ?currency ?language { ?it a :Country ; :currency ?currency ; :languages ?language }";

    public static void main(String[] args) {
        viaSnark();
        System.out.println("==============================");
        viaRDF4J();
    }

    private static void viaRDF4J() {
        StardogRepository repository = new StardogRepository("http://localhost:5820/bnode-test");
        repository.initialize();

        try (StardogRepositoryConnection connection = repository.getConnection()) {
            connection.begin();
            try (TupleQueryResult pops = connection.prepareTupleQuery(GET_COUNTRY).evaluate()) {
                Value country = pops.next().getValue("c");
                System.out.printf("With Country: %s\n", country);

                TupleQuery withCountry = connection.prepareTupleQuery(GET_DETAILS);
                withCountry.setBinding("it", country);
                try (TupleQueryResult bindings = withCountry.evaluate()) {
                    while (bindings.hasNext()) {
                        BindingSet next = bindings.next();
                        System.out.println("\t================================================");
                        for (String name : next.getBindingNames()) {
                            Value value = next.getValue(name);
                            System.out.printf("\t\t%s = %s\n", name, value);
                        }
                    }
                }
            }
            connection.commit();
        }

        repository.shutDown();
    }

    private static void viaSnark() {
        try (Connection connection = connection()) {
            connection.begin();
            connection.select(GET_COUNTRY).execute().stream()
                    .map(b -> b.get("c"))
                    .forEach(country -> {
                        System.out.printf("With Country: %s\n", country);

                        SelectQuery withCountry = connection.select(GET_DETAILS)
                                .parameter("it", country);

                        withCountry.execute().stream().forEach(bindings -> {
                            System.out.printf("\t%s\n", bindings);
                        });
                    });
            connection.commit();
        }
    }

    private static Connection connection() {
        return ConnectionConfiguration
                .to("bnode-test")
                .server("http://localhost:5820")
                .credentials("admin", "admin")
                .connect();
    }
}

```

The second run gives _::bnode\_873653f4\_39a0\_4f34\_983d\_c5431fd0b79b\_7059737_ for the bnode which looks like a double anonymisation - if that's such a thing 😉

Thanks

---

<div class="post-metadata">

**Author:** ![stephen](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/stephen/32/27_2.png) [@stephen](https://community.stardog.com/u/stephen)\
**Post date:** [March 19, 2019, 1:54pm UTC](https://community.stardog.com/t/differences-in-handling-of-bnodes-between-snark-and-rdf4j-apis/1529/2 "2019-03-19T13:54:21Z")

</div>

Hi Rory, and welcome!

This is indeed a bug in our RDF4J handling. I've located the root cause of it (specifically having to do with `TupleQuery#setBinding(BNode)` and will create a ticket to get the fix into our next release. Thanks for the report!

---

<div class="post-metadata">

**Author:** ![onto\_rory](https://avatars.discourse-cdn.com/v4/letter/o/c37758/32.png) [@onto\_rory](https://community.stardog.com/u/onto_rory)\
**Post date:** [April 8, 2019, 4:05pm UTC](https://community.stardog.com/t/differences-in-handling-of-bnodes-between-snark-and-rdf4j-apis/1529/3 "2019-04-08T16:05:57Z")

</div>

Just checking - was this fixed in 6.1.3 under _RDF4J connector improperly binding BNodes to query variables (#7001)_

If so, **awesome**. Thanks

---

<div class="post-metadata">

**Author:** ![stephen](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/stephen/32/27_2.png) [@stephen](https://community.stardog.com/u/stephen)\
**Post date:** [April 8, 2019, 4:37pm UTC](https://community.stardog.com/t/differences-in-handling-of-bnodes-between-snark-and-rdf4j-apis/1529/4 "2019-04-08T16:37:44Z")

</div>

Yes, 7001 was indeed the ticket created for this fix!
