Query returns same HGHandle for two different objects of the same class

13 views
Skip to first unread message

Aruna Bansal

unread,
Oct 11, 2017, 7:30:26 AM10/11/17
to HyperGraphDB
Hi,

I added object A of class Person (having 4 fields) using 
    hypergraph.add(A)   method where hypergraph is an instance of Hypergraph class. 

After that, I want to add another object B of the same Person class. Object A has values for all of its 4 fields whereas object B has values only for 2 fields. I give query:

      hg.findOne(graph, hg.and(hg.type(Person.class), hg.eq(B)))   to check the prior existence of B. But instead of null, the query returned the same HGHandle which was assigned for object A. 

I tried the same thing with two other objects of a different class, which worked fine. I don't understand the behaviour of hg.findOne/hg.findAll  (I tried both). Somebody please help me out.

Kind regards, 
Aruna



Borislav Iordanov

unread,
Oct 23, 2017, 1:35:40 AM10/23/17
to hyperg...@googlegroups.com
Hi Aruna,

First, hg.findOne just takes the first result while findAll iterates over and collects all of them. So  findOne returns null if and only if findAll return an empty list.

Now, when you use the hg.eq operator, HGDB will load the atoms in memory, full instantiated Java object, and then invoke the equals method on them. If you have defined Person.equals in a way that makes A and B equal, you will the HGHandle for A when querying with hg.eq(B). If that is not the case, can you please email a test case to reproduce the problem? The query you are showing is fairly straightforward: it just translates to scanning all atoms of type Person and invoking equals(B) on each of them, and return the first one that yields ’true’.

Cheers,
Boris

--
You received this message because you are subscribed to the Google Groups "HyperGraphDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hypergraphdb...@googlegroups.com.
To post to this group, send email to hyperg...@googlegroups.com.
Visit this group at https://groups.google.com/group/hypergraphdb.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages