Neo4j 无法将 java.lang.Long 字段 model.Authority.id 设置为 model.Authority

Neo4j Can not set java.lang.Long field model.Authority.id to model.Authority

我正在尝试让 Ne​​o4j 工作,但在尝试获取实体或保留实体时我最终遇到了这个错误,但无法弄清楚。

Caused by: java.lang.IllegalArgumentException: Can not set java.lang.Long field com.mycompany.mbi.dom.Authority.id to com.mycompany.mbi.dom.Authority at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167) ~[na:1.8.0_131] at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171) ~[na:1.8.0_131] at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:58) ~[na:1.8.0_131] at sun.reflect.UnsafeObjectFieldAccessorImpl.get(UnsafeObjectFieldAccessorImpl.java:36) ~[na:1.8.0_131] at java.lang.reflect.Field.get(Field.java:393) ~[na:1.8.0_131] at org.neo4j.ogm.metadata.FieldInfo.read(FieldInfo.java:373) ~[neo4j-ogm-core-3.0.0-RC1.jar:na] at org.neo4j.ogm.metadata.FieldInfo.readProperty(FieldInfo.java:432) ~[neo4j-ogm-core-3.0.0-RC1.jar:na] at org.neo4j.ogm.utils.EntityUtils.identity(EntityUtils.java:36) ~[neo4j-ogm-core-3.0.0-RC1.jar:na] at org.neo4j.ogm.context.EntityGraphMapper.mapEntity(EntityGraphMapper.java:211) ~[neo4j-ogm-core-3.0.0-RC1.jar:na] at org.neo4j.ogm.context.EntityGraphMapper.map(EntityGraphMapper.java:132) ~[neo4j-ogm-core-3.0.0-RC1.jar:na] at org.neo4j.ogm.session.delegates.SaveDelegate.save(SaveDelegate.java:79) ~[neo4j-ogm-core-3.0.0-RC1.jar:na] at org.neo4j.ogm.session.delegates.SaveDelegate.save(SaveDelegate.java:41) ~[neo4j-ogm-core-3.0.0-RC1.jar:na] at org.neo4j.ogm.session.Neo4jSession.save(Neo4jSession.java:451) ~[neo4j-ogm-core-3.0.0-RC1.jar:na] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_131] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_131] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_131] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_131] at org.springframework.data.neo4j.transaction.SharedSessionCreator$SharedSessionInvocationHandler.invoke(SharedSessionCreator.java:131) ~[spring-data-neo4j-5.0.0.RC2.jar:na] at com.sun.proxy.$Proxy95.save(Unknown Source) ~[na:na] at org.springframework.data.neo4j.repository.support.SimpleNeo4jRepository.save(SimpleNeo4jRepository.java:73) ~[spring-data-neo4j-5.0.0.RC2.jar:na] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_131] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_131] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_131] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_131] at org.springframework.data.repository.core.support.RepositoryComposition$RepositoryFragments.invoke(RepositoryComposition.java:377) ~[spring-data-commons-2.0.0.RC2.jar:na] at org.springframework.data.repository.core.support.RepositoryComposition.invoke(RepositoryComposition.java:200) ~[spring-data-commons-2.0.0.RC2.jar:na] at org.springframework.data.repository.core.support.RepositoryFactorySupport$ImplementationMethodExecutionInterceptor.invoke(RepositoryFactorySupport.java:604) ~[spring-data-commons-2.0.0.RC2.jar:na] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) ~[spring-aop-5.0.0.RC3.jar:5.0.0.RC3] at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:568) ~[spring-data-commons-2.0.0.RC2.jar:na] at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:549) ~[spring-data-commons-2.0.0.RC2.jar:na] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) ~[spring-aop-5.0.0.RC3.jar:5.0.0.RC3] at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:60) ~[spring-data-commons-2.0.0.RC2.jar:na] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) ~[spring-aop-5.0.0.RC3.jar:5.0.0.RC3] at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:294) ~[spring-tx-5.0.0.RC3.jar:5.0.0.RC3] at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98) ~[spring-tx-5.0.0.RC3.jar:5.0.0.RC3] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) ~[spring-aop-5.0.0.RC3.jar:5.0.0.RC3] at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139) ~[spring-tx-5.0.0.RC3.jar:5.0.0.RC3] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) ~[spring-aop-5.0.0.RC3.jar:5.0.0.RC3] at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) ~[spring-aop-5.0.0.RC3.jar:5.0.0.RC3] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) ~[spring-aop-5.0.0.RC3.jar:5.0.0.RC3] at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:61) ~[spring-data-commons-2.0.0.RC2.jar:na] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) ~[spring-aop-5.0.0.RC3.jar:5.0.0.RC3] at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) ~[spring-aop-5.0.0.RC3.jar:5.0.0.RC3] at com.sun.proxy.$Proxy101.save(Unknown Source) ~[na:na] at com.mycompany.mbi.security.InitSecurity.initApplication(InitSecurity.java:32) ~[classes/:na] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_131] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_131] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_131] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_131] at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:369) ~[spring-beans-5.0.0.RC3.jar:5.0.0.RC3] at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:312) ~[spring-beans-5.0.0.RC3.jar:5.0.0.RC3] at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:135) ~[spring-beans-5.0.0.RC3.jar:5.0.0.RC3] ... 23 common frames omitted

我的实体:

@NodeEntity
@public class Authority  {

public Authority() {
}

@Id
@GeneratedValue
private Long id;

@NotNull
@Size(min = 0, max = 50)
private String name;

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;
}

@Override
public String toString() {
    return "Authority{" +
        "name='" + name + '\'' +
        "}";
}

}

我的相关pom文件:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<artifactId>mbi-services</artifactId>
<version>1.0.0-SNAPSHOT</version>

<parent>
    <groupId>com.mycompany.mbi</groupId>
    <artifactId>mbi-all</artifactId>
    <version>1.0.0-SNAPSHOT</version>
</parent>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>${springBoot.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>${springCloud.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<repositories>
    <repository>
        <id>spring-milestones</id>
        <name>Spring Milestones</name>
        <url>https://repo.spring.io/libs-milestone</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>

<pluginRepositories>
    <pluginRepository>
        <id>jcenter</id>
        <name>JCenter</name>
        <url>https://jcenter.bintray.com/</url>
    </pluginRepository>
</pluginRepositories>

<properties>
    <!-- Plugin Properties -->
    <sonar.version>2.5</sonar.version>
    <springBoot.version>2.0.0.M3</springBoot.version>
    <springBoot.maven.version>1.5.7.RELEASE</springBoot.maven.version>
    <springCloud.version>Finchley.M2</springCloud.version>

    <!-- Dependency Properties -->
    <dropWizard.version>3.2.4</dropWizard.version>
    <gsonExtras.version>0.2.1</gsonExtras.version>
    <kassava.version>1.0.0</kassava.version>
    <neo4jDriver.version>1.5.0-alpha01</neo4jDriver.version>
    <neo4jOgmTest.version>3.0.0-RC1</neo4jOgmTest.version>
    <passay.version>1.0</passay.version>
    <randomBeans.version>3.7.0</randomBeans.version>
    <result.version>1.2.0</result.version>
    <slf4j.version>1.7.25</slf4j.version>
</properties>

<dependencies>
    <!-- Compile Dependencies -->
    <dependency>
        <groupId>au.com.console</groupId>
        <artifactId>kassava</artifactId>
        <version>${kassava.version}</version>
    </dependency>
    <dependency>
        <groupId>com.github.kittinunf.result</groupId>
        <artifactId>result</artifactId>
        <version>${result.version}</version>
    </dependency>
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
    </dependency>
    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
    </dependency>
    <dependency>
        <groupId>io.dropwizard.metrics</groupId>
        <artifactId>metrics-annotation</artifactId>
        <version>${dropWizard.version}</version>
    </dependency>
    <dependency>
        <groupId>org.danilopianini</groupId>
        <artifactId>gson-extras</artifactId>
        <version>${gsonExtras.version}</version>
    </dependency>     
    <dependency>
        <groupId>org.neo4j.driver</groupId>
        <artifactId>neo4j-java-driver</artifactId>
        <version>${neo4jDriver.version}</version>
    </dependency>
    <dependency>
        <groupId>org.passay</groupId>
        <artifactId>passay</artifactId>
        <version>${passay.version}</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>${slf4j.version}</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-ext</artifactId>
        <version>${slf4j.version}</version>
    </dependency>

    <!-- Spring Dependencies -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-neo4j</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-mail</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-eureka</artifactId>
    </dependency>
    <dependency>
        <groupId>org.thymeleaf</groupId>
        <artifactId>thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.thymeleaf</groupId>
        <artifactId>thymeleaf-spring5</artifactId>
    </dependency>

    <!-- Test Dependencies -->
    <dependency>
        <groupId>io.github.benas</groupId>
        <artifactId>random-beans</artifactId>
        <version>${randomBeans.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.neo4j</groupId>
        <artifactId>neo4j-ogm-test</artifactId>
        <version>${neo4jOgmTest.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.hamcrest</groupId>
        <artifactId>hamcrest-library</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

我想做的就是保存授权

Authority authAdmin = new Authority();
authAdmin.setName(AuthoritiesConstants.ADMIN);
authAdmin = authorityRepository.save(authAdmin);

我在 Spring Boot 2.0.0 M6 上遇到了同样的问题。通过恢复到 2.0.0 M5 使其正常工作。

注意 M4 有一个不同的问题,但 M3 也可以(尽管我认为没有理由比 M5 更进一步)