Neo4j无法设置java.lang.Long字段模型.Authority.id到model.Authority

时间:2017-10-09 12:44:10

标签: spring-boot neo4j maven-3 spring-data-neo4j-5

我试图让Neo4j工作,但是当我试图获得一个实体或者坚持一个实体时,我最终得到了这个错误,并且无法弄明白。

  

引起:java.lang.IllegalArgumentException:无法将java.lang.Long字段com.mycompany.mbi.dom.Authority.id设置为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]       在java.lang.reflect.Field.get(Field.java:393)〜[na:1.8.0_131]       在org.neo4j.ogm.metadata.FieldInfo.read(FieldInfo.java:373)〜[neo4j-ogm-core-3.0.0-RC1.jar:na]       在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]       在org.neo4j.ogm.context.EntityGraphMapper.mapEntity(EntityGraphMapper.java:211)〜[neo4j-ogm-core-3.0.0-RC1.jar:na]       在org.neo4j.ogm.context.EntityGraphMapper.map(EntityGraphMapper.java:132)〜[neo4j-ogm-core-3.0.0-RC1.jar:na]       在org.neo4j.ogm.session.delegates.SaveDelegate.save(SaveDelegate.java:79)〜[neo4j-ogm-core-3.0.0-RC1.jar:na]       在org.neo4j.ogm.session.delegates.SaveDelegate.save(SaveDelegate.java:41)〜[neo4j-ogm-core-3.0.0-RC1.jar:na]       在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]       在java.lang.reflect.Method.invoke(Method.java:498)〜[na:1.8.0_131]       在org.springframework.data.neo4j.transaction.SharedSessionCreator $ SharedSessionInvocationHandler.invoke(SharedSessionCreator.java:131)〜[spring-data-neo4j-5.0.0.RC2.jar:na]       在com.sun.proxy。$ Proxy95.save(未知来源)〜[na:na]       在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]       在java.lang.reflect.Method.invoke(Method.java:498)〜[na:1.8.0_131]       在org.springframework.data.repository.core.support.RepositoryComposition $ RepositoryFragments.invoke(RepositoryComposition.java:377)〜[spring-data-commons-2.0.0.RC2.jar:na]       在org.springframework.data.repository.core.support.RepositoryComposition.invoke(RepositoryComposition.java:200)〜[spring-data-commons-2.0.0.RC2.jar:na]       在org.springframework.data.repository.core.support.RepositoryFactorySupport $ ImplementationMethodExecutionInterceptor.invoke(RepositoryFactorySupport.java:604)〜[spring-data-commons-2.0.0.RC2.jar:na]       在org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)〜[spring-aop-5.0.0.RC3.jar:5.0.0.RC3]       在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]       在org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)〜[spring-aop-5.0.0.RC3.jar:5.0.0.RC3]       在org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:60)〜[spring-data-commons-2.0.0.RC2.jar:na]       在org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)〜[spring-aop-5.0.0.RC3.jar:5.0.0.RC3]       在org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:294)〜[spring-tx-5.0.0.RC3.jar:5.0.0.RC3]       在org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)〜[spring-tx-5.0.0.RC3.jar:5.0.0.RC3]       在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]       在org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)〜[spring-aop-5.0.0.RC3.jar:5.0.0.RC3]       在org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)〜[spring-aop-5.0.0.RC3.jar:5.0.0.RC3]       在org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)〜[spring-aop-5.0.0.RC3.jar:5.0.0.RC3]       在org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:61)〜[spring-data-commons-2.0.0.RC2.jar:na]       在org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)〜[spring-aop-5.0.0.RC3.jar:5.0.0.RC3]       在org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)〜[spring-aop-5.0.0.RC3.jar:5.0.0.RC3]       在com.sun.proxy。$ Proxy101.save(未知来源)〜[na:na]       在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]       在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]       在org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:135)〜[spring-beans-5.0.0.RC3.jar:5.0.0.RC3]       ...省略了23个常见帧

我的实体:

@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);

1 个答案:

答案 0 :(得分:1)

我在Spring Boot 2.0.0 M6上遇到了同样的问题。通过恢复到2.0.0 M5来实现它。

请注意M4有不同的问题,但M3也有效(虽然我认为没有理由再回头比M5更多)