Oct 8th, 2012, 11:32 AM
[Neo4j] Issues persisting a List/Set/Array of byte array
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
Oct 10th, 2012, 09:21 AM
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
Oct 11th, 2012, 10:29 AM
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.
Oct 12th, 2012, 02:40 AM
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