通过对象属性搜索

8tntrjer  于 2021-07-14  发布在  Java
关注(0)|答案(1)|浏览(443)

我有一个sidebarbox类,它有一个人作为属性。我想根据人的不同来买所有的杂烩。为此,我创建了以下仓库:

public interface SidebarRepository extends Neo4jRepository<SidebarBox, Long> {
    List<SidebarBox> findAllByPerson_Id(Long personId);
    List<SidebarBox> findAllByPerson(Person person);
}

如果我通过 findAllByPerson_Id 我根本没机会进入,如果我通过 findAllByPerson 程序崩溃,错误消息如下:

java.lang.IllegalStateException: Failed to execute CommandLineRunner
    at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:807) ~[spring-boot-2.4.2.jar:2.4.2]
    at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:788) ~[spring-boot-2.4.2.jar:2.4.2]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:333) ~[spring-boot-2.4.2.jar:2.4.2]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1311) ~[spring-boot-2.4.2.jar:2.4.2]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1300) ~[spring-boot-2.4.2.jar:2.4.2]
    at de.skillkiller.persondb.PersondbApplication.main(PersondbApplication.java:24) ~[classes/:na]
Caused by: org.springframework.data.mapping.MappingException: The property 'null' is not mapped to a Graph property!
    at org.springframework.data.neo4j.core.mapping.DefaultNeo4jPersistentProperty.getPropertyName(DefaultNeo4jPersistentProperty.java:247) ~[spring-data-neo4j-6.0.3.jar:6.0.3]
    at org.springframework.data.neo4j.repository.query.CypherQueryCreator.toCypherProperty(CypherQueryCreator.java:549) ~[spring-data-neo4j-6.0.3.jar:6.0.3]
    at org.springframework.data.neo4j.repository.query.CypherQueryCreator.createImpl(CypherQueryCreator.java:385) ~[spring-data-neo4j-6.0.3.jar:6.0.3]
    at org.springframework.data.neo4j.repository.query.CypherQueryCreator.create(CypherQueryCreator.java:240) ~[spring-data-neo4j-6.0.3.jar:6.0.3]
    at org.springframework.data.neo4j.repository.query.CypherQueryCreator.create(CypherQueryCreator.java:85) ~[spring-data-neo4j-6.0.3.jar:6.0.3]
    at org.springframework.data.repository.query.parser.AbstractQueryCreator.createCriteria(AbstractQueryCreator.java:119) ~[spring-data-commons-2.4.3.jar:2.4.3]
    at org.springframework.data.repository.query.parser.AbstractQueryCreator.createQuery(AbstractQueryCreator.java:95) ~[spring-data-commons-2.4.3.jar:2.4.3]
    at org.springframework.data.repository.query.parser.AbstractQueryCreator.createQuery(AbstractQueryCreator.java:81) ~[spring-data-commons-2.4.3.jar:2.4.3]
    at org.springframework.data.neo4j.repository.query.PartTreeNeo4jQuery.prepareQuery(PartTreeNeo4jQuery.java:69) ~[spring-data-neo4j-6.0.3.jar:6.0.3]
    at org.springframework.data.neo4j.repository.query.AbstractNeo4jQuery.execute(AbstractNeo4jQuery.java:82) ~[spring-data-neo4j-6.0.3.jar:6.0.3]
    at org.springframework.data.repository.core.support.RepositoryMethodInvoker.doInvoke(RepositoryMethodInvoker.java:137) ~[spring-data-commons-2.4.3.jar:2.4.3]
    at org.springframework.data.repository.core.support.RepositoryMethodInvoker.invoke(RepositoryMethodInvoker.java:121) ~[spring-data-commons-2.4.3.jar:2.4.3]
    at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.doInvoke(QueryExecutorMethodInterceptor.java:152) ~[spring-data-commons-2.4.3.jar:2.4.3]
    at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.invoke(QueryExecutorMethodInterceptor.java:131) ~[spring-data-commons-2.4.3.jar:2.4.3]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.3.jar:5.3.3]
    at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:80) ~[spring-data-commons-2.4.3.jar:2.4.3]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.3.jar:5.3.3]
    at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:123) ~[spring-tx-5.3.3.jar:5.3.3]
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:388) ~[spring-tx-5.3.3.jar:5.3.3]
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:119) ~[spring-tx-5.3.3.jar:5.3.3]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.3.jar:5.3.3]
    at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:137) ~[spring-tx-5.3.3.jar:5.3.3]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.3.jar:5.3.3]
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97) ~[spring-aop-5.3.3.jar:5.3.3]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.3.jar:5.3.3]
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215) ~[spring-aop-5.3.3.jar:5.3.3]
    at com.sun.proxy.$Proxy93.findAllByPerson(Unknown Source) ~[na:na]
    at de.skillkiller.persondb.PersondbApplication.lambda$demo$0(PersondbApplication.java:50) ~[classes/:na]
    at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:804) ~[spring-boot-2.4.2.jar:2.4.2]
    ... 5 common frames omitted

2021-02-23 18:51:36.308  INFO 34603 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Shutting down ExecutorService 'applicationTaskExecutor'
2021-02-23 18:51:36.311  INFO 34603 --- [           main] org.neo4j.driver.Driver                  : Closing driver instance 1555928242
2021-02-23 18:51:36.313  INFO 34603 --- [           main] org.neo4j.driver.ConnectionPool          : Closing connection pool towards localhost:7687
Disconnected from the target VM, address: '127.0.0.1:40261', transport: 'socket'

Process finished with exit code 1

命令行运行程序(短路):

Person person = new Person();
            person.setFirstname("Dieter");
            person.setLastname("Zufall");

            personRepository.save(person);

            SidebarBox sidebarBox = new SidebarBox("Test", person, new ArrayList<>());
            sidebarBox.addInformation(new SidebarBoxEntry("Key", "Nein"));
            sidebarBox.addInformation(new SidebarBoxEntry("AKey", "Nein"));

            sidebarRepository.save(sidebarBox);
            List<SidebarBox> a = sidebarRepository.findAll();
            List<SidebarBox> b = sidebarRepository.findAllByPerson_Id(person.getId());
            List<SidebarBox> c = sidebarRepository.findAllByPerson(person);

人:

@EqualsAndHashCode(callSuper = true)
@Node
@Data
@ToString(callSuper = true)
@NoArgsConstructor
@AllArgsConstructor
public class Person extends BasicNode {
    private String firstname;
    private String lastname;
    private String comment;
}

侧巴比妥:

@EqualsAndHashCode(callSuper = true)
@Node
@Data
@ToString(callSuper = true)
@NoArgsConstructor
@AllArgsConstructor
public class SidebarBox extends BasicNode{
    private String title;
    private Person person;
    private List<SidebarBoxEntry> information = new ArrayList<>();

    public void addInformation(SidebarBoxEntry entry) {
        information.add(entry);
    }

    public void removeInformation(SidebarBoxEntry entry) {
        information.remove(entry);
    }
}

基本节点:

@Data
@AllArgsConstructor
@NoArgsConstructor
public abstract class BasicNode {
    @Id
    @GeneratedValue
    private Long id;

    @DateLong
    @LastModifiedDate
    private Date changedAt = new Date();

    @DateLong
    @CreatedDate
    private Date enteredAt = new Date();
}

很遗憾,我不知道如何修复这个错误。你能告诉我怎样才能实现这样的疑问吗?

8iwquhpp

8iwquhpp1#

因为继承了 BasicNode springdataneo4j中有一个bug,它获取了错误的元信息,并且在您的例子中没有创建正确的类型( SidebarBox ). 更新将于本月晚些时候提供。同时你可以检查 6.0.6-SNAPSHOT 我用你的代码创建了一个例子https://github.com/meistermeier/neo4j-issues-examples/tree/master/relatedidquery 使用这个版本,它可以 List<SidebarBox> findAllByPerson_Id(Long personId) 对于即将发布的6.1版本,我们计划引入一个“按对象查找”来为您提供更大的灵活性。

相关问题