In model, in order to index some property, you should anotate it with @Index. SDN now adopt schema-based index policy, which means the Entity class name will be used as lable.
@NodeEntity @XmlRootElement @JsonAutoDetect @JsonIgnoreProperties(ignoreUnknown = true) public class User { @Indexed private String name; @Indexed(unique = true) private String userId; @Indexed private String phoneNumber; ....
In the above codes, SDN will produce tow labels for this modle User, _User.
If we want multiply lables for a modle, we could do this by following
@Labels private Set<String> lables; public Set<String> getLables() { return lables; } public void setLables(Set<String> lables) { this.lables = lables; } public void addLable(String lable) { if (this.lables == null) this.lables = new HashSet<String>(); lables.add(lable); } public void delLable(String lable){ if(this.lables!=null & this.lables.contains(lable)) lables.remove(lable); }
We can add lables for a node in extention
@Path("/addLable/active/{userName}") @GET @Produces(MediaType.APPLICATION_JSON) public Response activeUser(final @PathParam("userName") String userName) throws JSONException { try (Transaction tx = template.getGraphDatabaseService().beginTx()) { User user = userRepo.getUserByName(userName); if(user != null){ user.addLable(FIFOLabels.ActiveUser.name()); userRepo.saveOnly(user); }else{ return Response.status(Status.NOT_FOUND).entity("User doesn't exist").build(); } tx.success(); } return Response.status(Status.OK).entity(OK_MSG).build(); }
----------------------------------------------------------------------
But a failure comes in other modle using @Lables,
java.lang.NullPointerException at org.springframework.data.neo4j.fieldaccess. LabelFieldAccessorFactory$LabelFieldAccessor.setValue (LabelFieldAccessorFactory.java:73) at org.springframework.data.neo4j.fieldaccess. DefaultEntityState.setValue(DefaultEntityState.java:113)
Model Cods
@Labels private Set<String> lables; public Set<String> getLables() { return lables; } public void setLables(Set<String> lables) { this.lables = lables; } public void addLable(String lable) { if (this.lables == null) this.lables = new HashSet<String>(); lables.add(lable); } public void delLable(String lable) { if (this.lables != null & this.lables.contains(lable)) lables.remove(lable); } @Indexed(indexType = IndexType.POINT, indexName = "TaskLocation") String wkt; public void setLocation(float lon, float lat) { this.wkt = String.format("POINT( %.2f %.2f )", lon, lat); } public Task() { } public Task(String taskId, String title, String description) { this.taskId = taskId; this.title = title; this.description = description; }
The reasons I guess is that I used legency Index type .
@Indexed(indexType = IndexType.POINT, indexName = "TaskLocation") String wkt;
But,when I save a Task node by set it's lable, there is no error.
@Path("/addTask") @POST @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public Response addTask(Task task) { logger.info("############# add new task ########################"); logger.info("task:" + task.toString()); task.addLable("NewTask"); taskRepo.saveOnly(task); return Response.status(Status.OK).entity(OK_MSG).build(); }
When comment this add lable command, error comes
//task.addLable("NewTask");
Why?
Labels Set not initialized when using @Labels annotation
https://jira.spring.io/browse/DATAGRAPH-541
It turns out that this is a bug in SDN.
Good news is that I solved this problem by manually initilize @Labels filed in constuctor
public Task() { this.lables = new HashSet<String>(); this.lables.add("Task"); this.lables.add("_Task"); }
References
http://graphaware.com/neo4j/2015/01/16/neo4j-graph-model-design-labels-versus-indexed-properties.html
http://stackoverflow.com/questions/22075802/spring-data-neo4j-3-0-0-labels-support
http://stackoverflow.com/questions/28272953/how-to-use-labels-spring-data-neo4j
http://stackoverflow.com/questions/28475023/how-to-add-labels-to-nodes-using-spring-data-neo4j
https://github.com/spring-projects/spring-data-neo4j/blob/15cc8418ed4d429a952b86f788717add8a93f76c/spring-data-neo4j-aspects/src/test/java/org/springframework/data/neo4j/aspects/Person.java
相关推荐
Neo4j Vue 安装步骤 克隆或下载该库到本地 下载neo4j并安装到本地,启动neo4j服务 进入到该工程的根目录,输入命令:npm run update进行npm包的导入 使用命令:npm run dev启动该工程 默认端口是:8081 neo4j账号...
Neo4j Vue 安装步骤 克隆或下载该库到本地 下载neo4j并安装到本地,启动neo4j服务 进入到该工程的根目录,输入命令:npm run update进行npm包的导入 使用命令:npm run dev启动该工程 默认端口是:8081 neo4j账号...
仍然可以在下访问使用SDN 5 + OGM的先前版本。分支。 笔记有关具有相同数据集的Spring Data Neo4j 6的更广泛概述,可以访问分支。 上详细描述了示例项目。 该项目使用Java 11。堆栈这些是我们的Web应用程序的组件: ...
宁静的 Neo4j 2.1+ 用于 Neo4j 宁静 apis 的 Sails.js 水线适配器安装从 NPM 安装。 $ npm install sails-restful-neo4j兼容性这与风帆 0.10 及更高版本兼容帆配置将以下配置添加到 config/connections.js 文件中: ...
neo4j:所有人的图表
DR $ docker run --name neo4j bitnami/neo4j:latestDocker撰写$ curl -sSL https://raw.githubusercontent.com/bitnami/bitnami-docker-neo4j/master/docker-compose.yml > docker-compose.yml$ docker-compose up...
imap2neo4j: imap2neo4j imapServer imapUsername imapPassword imapMailbox neo4jServer [neo4jUsername] [neo4jPassword] [paging, eg import by batches of 1000] [specific range of messages, eg 50
通过在 conf/neo4j-server.properties 中添加一行来配置 Neo4j: org.neo4j.server.thirdparty_jaxrs_classes=org.neo4j.example.unmanagedextension=/example 启动 Neo4j 服务器。 写评论 curl ...
Sublime Text 2/3 插件:Neo4j Sublime 是最好的跨平台编辑器之一,所以我想为什么不创建一个简单的 Neo4j 插件呢?... 编辑用户名和密码(默认为neo4j:neo) 结果显示在控制台中(Ctrl+~)打开C
egg-neo4j Neo4j用于鸡蛋框架。安装$ npm i egg-neo4j --save用法// {app_root}/config/plugin.jsexports . neo4j = { enable : true , package : 'egg-neo4j' ,} ;配置// {app_root}/config/config.default....
NBD_Tutorials_Neo4J:PJATK NDB教程的Neo4J分配
schemaless-graphql-neo4j 将无类型的动态GraphQL查询转换为Cypher。 签出,以更好地查看您可以编写的查询。入门$ npm install schemaless-graphql-neo4j :warning: 图书馆尚未发布操场您可以开始使用开发人员游乐场...
This book will take you from the installation of Neo4j through to building a full application with Neo4j at its heart, and everything in between. Using this book, you'll get everything up and ...
Neo4j Vue安装步骤克隆或下载该库到本地下载neo4j并安装到本地,启动neo4j服务进入到该工程的根目录,输入命令:npm run update进行npm包的导入使用命令:npm run dev启动该工程默认端口是:8081 neo4j账号信息: ...
spring-data-neo4j SDN 4
Neo4j Neo4j 是一个高度可扩展、健壮(完全 ACID)的原生图形数据库。 Neo4j 被全球数以千计的领先企业、初创公司、企业和政府用于任务关键型应用程序。 使用存储库上的 Dockerfile,您就可以使用 docker neo4j ...
适用于Node.js的Neo4j REST API包装器 主分支: 开发分支: 安装 npm install node-neo4j --save 用法 为了使用该库,您必须创建一个应用并添加或在本地安装它。 如果您使用的是OS XI,则强烈建议通过安装Neo4j。 ...
适用于Neo4j的GORM 该项目使用Bolt Java驱动程序为Neo4j 3.x图形数据库实现 。 有关更多信息,请参见以下链接: 对于当前的开发版本,请参见以下链接:
Neo4j 用于将Neo4j图形数据库作为Hackolade数据建模目标的插件。 Hackolade通过插件体系结构公开了其核心数据建模引擎。 每个插件都将Hackolade数据建模功能应用于特定的目标技术,无论是静态数据(数据库)还是...
poc-neo4j 这是有关neo4j功能的POC 启动neo4j数据库docker run -p7474:7474 -p7687:7687 -e NEO4J_AUTH = neo4j / s3cr3t neo4j 可以通过浏览器访问 直接创建数据: 创建(Inception:电影{title:'Inception',...