[SDN 3.0.2] / Potential bug with @Fetch annotation

8 views
Skip to first unread message

Michael Azerhad

unread,
Apr 17, 2014, 9:30:16 PM4/17/14
to ne...@googlegroups.com
Hi,

I know that SDN 3.X.X is not full tested yet but I come across this potential bug, and I would like to know if it is a "known" one:

I have an acceptance test written using Specs2 (using a pretty DSL) containing this:

meetingRepository.findAllParticipants(meetingId) must have size 3        //works, asserting 3, since it's a custom query I wrote in the meetingRepository to prove that the second line doesn't work

meetingRepository
.findById(meetingId).participants must have size 3    // instead of asserting 3, it always displays "containing 2, not 3"

My custom query is:

@Query("MATCH (m:Meeting {_id: {0}})<-[:PARTICIPATES]-(participant) return participant")
def findAllParticipants(meetingId: String): EndResult[Participant]


The bug therefore concerns the @Fetch annotation that is above the Participants Set, in the class Meeting:

@org.springframework.data.neo4j.annotation.Fetch
@org.springframework.data.neo4j.annotation.RelatedTo(`type` = "PARTICIPATES", direction = Direction.INCOMING)
var participants: java.util.Set[Participant] = new util.HashSet[Participant]

I don't figure out why it doesn't return all the participants but only 2. 
I even test with the Rest mode database, to be sure to see the 3 participants saved, just before the line "meetingRepository.findById(meetingId).participants must have size 3"  is executed. And there are the 3 elements as expected in the rest database.

Is it possible to check it with a possible SDN unit test ?  If there is one concerning the fetch annotation of course.

Thanks a lot,

Michael

Michael Hunger

unread,
Apr 18, 2014, 12:42:03 AM4/18/14
to ne...@googlegroups.com
Perhaps two are the same and so reduced to one in the set

What happens if you add distinct to your cypher query?

Sent from mobile device
--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Michael Azerhad

unread,
Apr 18, 2014, 11:17:11 AM4/18/14
to ne...@googlegroups.com
Hi Michael,

You put me on the track.

After investigation, I would not define the hashcode well. 
I had:

override def hashCode(): Int = {
   
if (_id == null)
     
0
   
else
      _id
.hashCode()
 
}


Replaced by:

override def hashCode(): Int = {
   
if (_id == null)
     
System.identityHashCode(this)
   
else
      _id
.hashCode()
 
}


I put 0 since I thought that there would never be a case where the business `_id` would be null, since i use @fetch so when I retrieve an attached entity, I expected to be fully complete.
That was not the case :)  I imagine that the fetch process firstly initializes the list only with the node id (not the business id of course), explaining why two elements with 0 as hashcode would be entered in collision, thus losing one.  AND THEN completes them with all the fetched attributes.

Thanks a lot,

Michael
Reply all
Reply to author
Forward
0 new messages