简体   繁体   English

在Cypher CREATE子句中指定属性的基本类型

[英]Specifying the primitive type of a property in a Cypher CREATE clause

Contrary to what's possible with the Java API, there doesn't seem to be a way to specify whether a numeric property is a byte , short , int or long : 与Java API的可能性相反,似乎没有办法指定数字属性是byteshortint还是long

CREATE (n:Test {value: 1}) RETURN n

always seems to create a long property. 似乎总是创造一个long财产。 I've tried toInt() , but it is obviously understood in the mathematical sense of "integer" more than in the computer data type sense. 我试过toInt() ,但显然在数学意义上的“整数”比在计算机数据类型意义上更容易理解。

Is there some way I'm overlooking to actually force the type? 有什么方法我忽略了实际强迫这种类型?

We have defined a model and want to insert test data using Cypher statements, but the code using the data then fails with a ClassCastException since the types don't match. 我们已经定义了一个模型,并希望使用Cypher语句插入测试数据,但是由于类型不匹配,使用数据的代码会因ClassCastException失败。

If you run your cypher queries with the embedded API then you can provide parameters in a hashmap with the correctly typed values. 如果使用嵌入式API运行cypher查询,则可以在散列映射中使用正确键入的值提供参数。

For remote users it doesn't really matter as it goes through JSON serialization back and forth which looses the type information anyway. 对于远程用户来说,它并不重要,因为它来回传递JSON序列化,无论如何都会丢失类型信息。 So it is just "numeric". 所以它只是“数字”。

Why do you care about the numeric type? 你为什么关心数字类型?

you can also just use ((Number)n.getProperty("value")).xxxValue() (xxx = int,long,byte) 你也可以使用((Number)n.getProperty("value")).xxxValue() (xxx = int,long,byte)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM