使用NEO4J-JDBC-Driver在Java EE应用程序中的多个语句时出错

时间:2014-12-16 23:54:13

标签: java jdbc neo4j cypher

Stack:TOMEE / NEO4J 2.1.6社区版

我在做什么:

  • 将一组JSON对象发布到Java JAX-RS Web服务
  • 解析JSON并创建Cypher查询
  • 尝试执行Cypher查询并以JSON格式返回结果。

问题:

为避免重复节点创建,在不增加应用程序代码中的额外开销的情况下,我正在使用" CREATE CONSTRAINT ON"

这就是我的Cypher看起来像

CREATE (EVENTS:Events {name:'nm_Events',value:'256',label:'lb_Events'} )  
CREATE CONSTRAINT ON (EVENTS:Events) ASSERT EVENTS.name IS UNIQUE 
CREATE (LOGOUTS:Logouts {name:'nm_Logouts',value:'4',label:'lb_Logouts'} )  
CREATE CONSTRAINT ON (LOGOUTS:Logouts) ASSERT LOGOUTS.name IS UNIQUE 
CREATE (ACCIDENTAL_CLICKS:Accidental_Clicks {name:'nm_AccidentalClicks',value:'4',label:'lb_AccidentalClicks'} )  
CREATE CONSTRAINT ON (ACCIDENTAL_CLICKS:Accidental_Clicks) ASSERT ACCIDENTAL_CLICKS.name IS UNIQUE 
CREATE (INTERACTIONS:Interactions {name:'nm_Interactions',label:'lbl_interactions'} )  
CREATE CONSTRAINT ON (INTERACTIONS:Interactions) ASSERT INTERACTIONS.name IS UNIQUE 
CREATE (BUTTONS:Buttons {name:'nm_buttons',label:'lbl_buttons'} )  
CREATE CONSTRAINT ON (BUTTONS:Buttons) ASSERT BUTTONS.name IS UNIQUE 
CREATE (GROUP_BUTTON:Group_Button {name:'nm_GroupButton',value:'54',label:'lb_GroupButton'} )  
CREATE CONSTRAINT ON (GROUP_BUTTON:Group_Button) ASSERT GROUP_BUTTON.name IS UNIQUE 
CREATE (DELETE_BUTTON:Delete_Button {name:'nm_DeleteButton',value:'454',label:'lb_DeleteButton'} )  
CREATE CONSTRAINT ON (DELETE_BUTTON:Delete_Button) ASSERT DELETE_BUTTON.name IS UNIQUE 
CREATE (LOGIN_BUTTON:Login_Button {name:'nm_LoginButton',value:'256',label:'lb_LoginButton'} )  
CREATE CONSTRAINT ON (LOGIN_BUTTON:Login_Button) ASSERT LOGIN_BUTTON.name IS UNIQUE 
CREATE UNIQUE (LOGOUTS)-[:CHILD_OF]->(EVENTS) 
CREATE UNIQUE (ACCIDENTAL_CLICKS)-[:CHILD_OF]->(EVENTS) 
CREATE UNIQUE (DELETE_BUTTON)-[:CHILD_OF]->(GROUP_BUTTON) 
CREATE UNIQUE (GROUP_BUTTON)-[:CHILD_OF]->(BUTTONS) 
CREATE UNIQUE (LOGIN_BUTTON)-[:CHILD_OF]->(BUTTONS) 
CREATE UNIQUE (BUTTONS)-[:CHILD_OF]->(INTERACTIONS)

问题:

在NEO4J的控制台中执行时会出现错误

Invalid input 'N': expected 'p/P' (line 2, column 20)
"CREATE CONSTRAINT ON (EVENTS:Events) ASSERT EVENTS.name IS UNIQUE "
                    ^

我读到你不能在控制台中执行多行语句,但在使用JDBC代码时也会遇到同样的问题。

请帮忙。

1 个答案:

答案 0 :(得分:0)

您不能混合使用DML和DDL,先建立约束/索引,然后再创建数据。

同样在控制台中,每个都是单独的语句和事务,如果你想对JDBC做同样的事情,在循环中运行语句列表,单独执行它们。