It worked! Thank you very much Michael.
Τη Δευτέρα, 9 Φεβρουαρίου 2015 - 12:34:33 π.μ. UTC+2, ο χρήστης Michael Hunger έγραψε: > > You can't use Object arrays, only arrays of strings, numbers or booleans. > > and this doesn't work as it only stores the java-to-string representation > of an array, which is useless: > > nodeProps.put(predicateName, valuesList.toString()); > > > you shouldn't use exceptions for control-flow you can check > > value.getClass().isArray() > and you can do class.getComponentType() to check the type of the array > > Michael > > Am 08.02.2015 um 23:25 schrieb Aris Fergadis <[email protected] > <javascript:>>: > > My new code snippet is the following: > > Map<String, Object> nodeProps = db.getNodeProperties(subjectNode); > if (nodeProps.get(predicateName) != null) { > try { // Property values might be an array > Object[] values = (Object[]) nodeProps.get(predicateName); > ArrayList<Object> valuesList = new ArrayList<>(Arrays.asList(values)); > valuesList.add(value); > nodeProps.put(predicateName, valuesList.toArray(new > Object[valuesList.size()])); > } catch (ClassCastException cce) { // or just a value > Object v = nodeProps.get(predicateName); > Object[] valuesList = new Object[]{v, value}; > nodeProps.put(predicateName, valuesList.toString()); > } > } else { > nodeProps.put(predicateName, value); > } > db.setNodeProperties(subjectNode, nodeProps); > > > But in the graph I get: synonym [Ljava.lang.Object;@788ab663 > I get an exception if I use: > > nodeProps.put(predicateName, valuesList.toString()); > > Which is the right way to put the Object array in nodeProprs.put? > > Τη Κυριακή, 8 Φεβρουαρίου 2015 - 10:28:10 μ.μ. UTC+2, ο χρήστης Aris > Fergadis έγραψε: >> >> I am using neo4j community 2.1.6 edition and I have already posted a >> question >> <http://stackoverflow.com/questions/28397457/neo4j-batchinserter-using-setnodeproperties-to-set-an-array-with-values> >> >> in stackoverflow. >> >> My task is to import an ontology to Neo. So I read triples and insert >> nodes, properties and relations. Many of my triples define multiple values >> for the same property of a node. I want to set those values as an array in >> the property. Unfortunately, the method >> >> *setNodeProperties >> <http://neo4j.com/api_docs/2.0.0/org/neo4j/unsafe/batchinsert/BatchInserter.html#setNodeProperties%28long,%20java.util.Map%29>*(long >> node, >> Map >> <http://docs.oracle.com/javase/7/docs/api/java/util/Map.html?is-external=true> >> <String >> <http://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true> >> ,Object >> <http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html?is-external=true> >> > properties)seems to doesn't fit my needs. >> >> Is there any way to achieve my goal? >> > > -- > 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 [email protected] <javascript:>. > For more options, visit https://groups.google.com/d/optout. > > > -- 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 [email protected]. For more options, visit https://groups.google.com/d/optout.
