简体   繁体   English

Spring启动neo4j @NodeEntity与Integer属性抛出错误

[英]Spring boot neo4j @NodeEntity with Integer property throwing error

When I use data type as Integer/int for field rowStatusId, I am able to save node to neo4j database using .save() method but while retrieving the record using findByName(String name), system throwing error as below (error occurred at "LineItemStatus status = lineItemStatusRepository.findByName("New");" in service ).当我将数据类型用作字段 rowStatusId 的 Integer/int 时,我可以使用 .save() 方法将节点保存到 neo4j 数据库,但是在使用 findByName(String name) 检索记录时,系统抛出如下错误(错误发生在“ LineItemStatus status = lineItemStatusRepository.findByName("New");" in service )。 I am not receiving any error when I change the data type to Long.当我将数据类型更改为 Long 时,我没有收到任何错误。

Can't we use Integer?我们不能使用整数吗? or do I need to include any other dependencies?还是我需要包含任何其他依赖项? Please help me.请帮我。

Caused by: org.neo4j.ogm.exception.core.MappingException: Error mapping GraphModel

Caused by: org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.Long] to type [int]

Below is my code下面是我的代码

import org.neo4j.ogm.annotation.GeneratedValue;
import org.neo4j.ogm.annotation.Id;
import org.neo4j.ogm.annotation.NodeEntity;

@NodeEntity
public class LineItemStatus {
    @Id
    @GeneratedValue
    private Long id;
    private String name;
    private String description;
    private int rowStatusId;

    public LineItemStatus(String name, String description, int rowStatusId) {
        this.name = name;
        this.description = description;
        this.rowStatusId = rowStatusId;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public int getRowStatusId() {
        return rowStatusId;
    }

    public void setRowStatusId(int rowStatusId) {
        this.rowStatusId = rowStatusId;
    }
}

reopsioty:重新定位:

import com.ns.tbe.model.nodes.LineItemStatus;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface LineItemStatusRepository extends Neo4jRepository<LineItemStatus, Long> {
    LineItemStatus findByName(String name);
}

Service:服务:

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LineItemStatusService {
    @Autowired
    LineItemStatusRepository lineItemStatusRepository;

    public void saveLineItemStatus() {
        lineItemStatusRepository.save(new LineItemStatus("New", "new", 1));
        lineItemStatusRepository.save(new LineItemStatus("Modified", "modified", 1));
        lineItemStatusRepository.save(new LineItemStatus("Deleted", "deleted", 1));

        LineItemStatus status = lineItemStatusRepository.findByName("New");
    }
}

build.gradle file: build.gradle 文件:

plugins {
    id 'org.springframework.boot' version '2.3.0.RELEASE'
    id 'io.spring.dependency-management' version '1.0.9.RELEASE'
    id 'java'
}

group = 'com.ns'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'

repositories {
    mavenCentral()
}

dependencies {

    implementation 'org.springframework.boot:spring-boot-starter-data-neo4j'
    compile group: 'org.neo4j', name: 'neo4j-ogm-bolt-driver', version: '3.2.11'
    compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.10'
    implementation 'org.springframework.boot:spring-boot-starter'
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
}

test {
    useJUnitPlatform()
}

Application Properties:应用属性:

spring.data.neo4j.uri=bolt://localhost:7687
spring.data.neo4j.username=neo4j
spring.data.neo4j.password=secret

Drivers tend to store integers as longs.驱动程序倾向于将整数存储为长整型。 Here is a nicely detailed explanation of what is going on: https://michael-simons.github.io/neo4j-sdn-ogm-tips/understand_the_type_system.html .这是对正在发生的事情的详细解释: https : //michael-simons.github.io/neo4j-sdn-ogm-tips/understand_the_type_system.html

To simplify things, you may want to change rowStatusId to be of type long .为了简化问题,你可能要更改rowStatusId为类型的long

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

相关问题 Spring Data Neo4j在一个NodeEntity中合并不同的类 - Spring Data Neo4j merge different classes in one NodeEntity 如何使用Spring Data Neo4j在NodeEntity中持久保存Map(java.util.Map)对象? - How do I use Spring Data Neo4j to persist a Map (java.util.Map) object inside an NodeEntity? Spring Neo4J REST错误-nodeStateTransmitter - Spring Neo4J REST error - nodeStateTransmitter spring-data-neo4j删除nodeEntity和所有引用的节点 - spring-data-neo4j remove nodeEntity and all referenced nodes 带有Spring Boot和Spring Data Neo4j的REST API - REST API with Spring Boot and Spring Data Neo4j 无法使用 neo4j ogm 2.0.6、spring boot 和远程 NEO4J 社区服务器 3.1.1 在 POJO 中“拥有”集合属性 - cannot hydrate "owns" collection property in POJO using neo4j ogm 2.0.6, spring boot, and remote NEO4J Community server 3.1.1 Spring Boot - 连接到Neo4j和MySQL数据源 - Spring Boot - Connect to Neo4j and MySQL datasources @Transactional:在事务结束时不提交; 使用Spring Boot和neo4j - @Transactional: Not committing at end of transaction; using Spring Boot and neo4j 重新启动Spring Boot应用程序时Neo4j返回null - Neo4j returns null when restart spring boot application 在 Spring Boot 中无法通过 Neo4j 实现 CRUD 操作 - Cannot implement CRUD operations through Neo4j in Spring Boot
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM