Results 1 to 4 of 4

Thread: [Neo4j] Issues persisting a List/Set/Array of byte array

  1. #1
    Join Date
    Oct 2012
    Posts
    10

    Default [Neo4j] Issues persisting a List/Set/Array of byte array

    Hi Everyone,

    I ran into some issues with byte array.

    I was able to successfully persist and read "byte[]" in neo4j database.
    I verified them using neoeclipse (a graph database viewer) and found they are appearing as byte[] datatype.

    Next I tried to persist List<byte[]> or Set<byte[]> or byte[][]. (i.e., [[1,2,3], [4,5,6]....] )
    After persisting, I found all of them are appearing as String[] (i.e., [ "1,2,3", "4,5,6", ... ] ) in the database.
    When I read them back I was able to read them if I had persisted them as List<byte[]> or Set<byte[]>. However in case of byte[][], it was throwing a spring framework exception (Cannot convert String to byte array), while reading back.

    I have 2 questions
    1) Does spring data framework support higher dimensional arrays yet?
    2) Since the List<byte[]> and Set<byte[]> can be successfully persisted and read back, are they converting String "1,2,3" to byte[] [1,2,3] automatically internally ? Is it really supported by Spring data and can I safely use them ?

    Thanks in advance
    Faisal

  2. #2
    Join Date
    May 2012
    Posts
    107

    Default

    faisala,

    Firstly, Neo4j support simple types (boolean, int, long, double, String etc) and arrays of simple types (int[], float[] etc). SDN supports those directly too, as well as enums and java.util.Date, additionally.

    For other types - MyFooBar or long[][][][][], we delegate to Spring's conversion support, specifically GenericConversionService (http://static.springsource.org/sprin...onService.html), which is configurable outside of SDN itself. This is the same conversion support you get for other Spring services, it is a Spring Core library.

    So if you want to store custom types you need to go and write your own converters and install them, and here is an example of how to do that: https://github.com/SpringSource/spri...sionTests.java

    Regards,

    Lasse

  3. #3
    Join Date
    Oct 2012
    Posts
    10

    Default

    Thanks Lasee for your reply.

    One other question: I want to persist something like List of Objects. What kind of data structure will be useful in this case ?
    Set wont work as they don't preserve the sequence.

    And how do we make sure that the converter i wrote (for converting byte[] to string/long etc) on lets say List<byte[]> not a regular byte[].

  4. #4
    Join Date
    Jan 2011
    Location
    Dresden, Germany
    Posts
    525

    Default

    Write a converter of your objects to strings (json) or byte[] (java serialization).

    Otherwise you can also decompose your objects into node-entities and create a linked list of those.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •