当前位置: 首页 > 知识库问答 >
问题:

不存在主SDN标签。。(即以u开头的一个)

师成弘
2023-03-14

Spring data neo4j版本:3.3.0。发布Neo4j版本:2.2.2

当我试图查询在Spring数据存储库中公开的默认方法时,我遇到了以下异常。

personRepository.findAll(getDefaultPageable());

public static Pageable getDefaultPageable() {
    BiFunction<Integer, Integer, Pageable> biFunction = PageRequest::new; // Method reference syntax in action
    return biFunction.apply(DEFAULT_PAGE_NUMBER, DEFAULT_PAGE_SIZE);
}

造成原因:java.lang.IllegalState异常:没有主SDN标签存在...(即一个以_开始)在org.springframework.data.neo4j.support.typerepresentation.LabelBasedNodeTypeExportationStrategy.readAliasfrom(LabelBasedNodeTypeExportationStrategy.java:136)在org.springframework.data.neo4j.support.typerepresentation.LabelBasedNodeTypeExportationStrategy.readAliasfrom(org.springframework.data.neo4j.support.mapping.TRSTypeAliasAccessor.readAliasfrom(TRSTypeAliasAccessor.java:36)org.springframework.data.neo4j.support.mapping.TRSTypeAliasAccessor.readAliasfrom(TRSTypeAliasAccessor.java:26)org.springframework.data.convert.DefaultTypeMapper.read类型(DefaultTypeMapper.java:102)在org.springframework.data.convert.DefaultTypeMapper.getDefaultedTypeToBeuse(DefaultTypeMapper.java:165)在org.springframework.data.convert.DefaultTypeMapper. readType(DefaultTypeMapper. java: 142)在org. springframework. data. neo4j. support. map。Neo4jEntityConverterImp. read(Neo4jEntityConverterInp. java: 77)在org. springframework. data. neo4j. support.映射。在org. springframework. data. neo4j. support.映射中读取(Neo4jEntityPersis. java: 170)$CachedConver. read。在org. springframework. data. neo4j. support.映射。在org. springframework. data. neo4j. support上的Neo4jEntityPersis. project(Neo4jEntityPersis. java: 216)。Neo4jTemplate. project to(Neo4jTemplate. java: 241)at org. springframework. data. neo4j. support.转换。EntityResultConverter. doConver(EntityResultConverter. java: 73)在org. springframework. data. neo4j.转换。DefaultConverter(DefaultConverter. java: 44)在org. springframework. data. neo4j. support.转换。EntityResultConverter.转换(EntityResultConverter. java: 165)在org. springframework. data. neo4j.转换。QueryResultBuilder1美元. underlyingObjectToObject(QueryResultBuilder. java: 86),网址为org. neo4j. helper. Collection。IterableWrapper$MyIteratorWrapper. underlyingObjectToObject(IterableWrapper. java: 57),网址为org. neo4j. helper.集合。下一步(IteratorWrapper. java: 47)在org. springframework. data. neo4j. repository。子列表(AbstractGraphReposory. java: 371)在org. springframework. data. neo4j. repository。java: 355)在org. springframework. data. neo4j. repository。FindAll(AbstractGraphReposory. java: 321)at sun.反射。nativemethod odAccessorImp. invke0(本机方法)在sun.反射。NativeMEDAccessorInp. invoke(NativeMEDAccessorInp. java: 62)在sun. reff。在java. lang.反射中调用(委托方法访问或执行. java: 43)。在org. springframework. data. repository. core. support上调用(method. java: 497)。RepositoryFactorySupport$QueryExecutorMETHODInterceptor. JAVA: 414)在org. springframework. data. repository. core. support。RepositoryFactorySupport$QueryExecutorMultiodInterceptor. doInvoke(RepositoryFactorySupport. java: 399)位于org. springframework. data. repository. core. support。RepositoryFactorySupport$QueryExecutorMultiodInterceptor. invoke(RepositoryFactorySupport. java: 371)位于org. springframework. aop. framework。java: 179)在org. springframework. data. project。在org. springframework. aop. framework上调用(DefaultMEODInvokingMEDInterceptor. java: 61)。java: 179),网址为org. springframework.事务性.拦截器。TransactionInterceptor1美元。在org. springframework.事务性.拦截器上的TransactionAshooSupport. invkeBackinTransaction(TransactionAshooSupport. java: 281)。调用(TransactionInterceptor. java: 96)在org. springframework. aop. framework。在org. springframework. dao. support上继续(Reflropemethod odInvocation. java: 179)。在org. springframework. aop. framework中调用(PeristextExceptionTranslationInterceptor. java: 136)。java: 179)在org. springframework. aop. framework。jdkDynamicAopProxy. invoke(JdkDynamicAopProxy. java: 207)在com. sun. proxy。$Proxy60. findAll(未知来源)at sun. reff.nativemethod odAccessorImp. invke0(本机方法)在sun.反射。NativeMEDAccessorInp. invoke(NativeMEDAccessorInp. java: 62)在sun. reff。在java. lang.反射中调用(委托方法访问或执行. java: 43)。在org. springframework. aop. support上调用(method. java: 497)。在org. springframework. aop. framework.jdkDynamicAopProxy. invoke(JdkDynamicAopProxy. java: 201)在com. sun. proxy。$Proxy61. findAll(未知来源)

我真的不想在这里做任何复杂的事情,所以我很难理解我是否真的应该引入一个带有下划线前缀标签的自定义查询,并使用注释@query?Spring数据中的默认方法是否只适用于SDN?

我修改了cypher查询,结果仍然是相同的错误。

使用者:java.lang.IllegalStateExcema:没有主SDN标签存在...(即以_开始的一个)在org.springframework.data.neo4j.support.typerepresentation.LabelBasedNodeTypePresationStrategy.readAliasfrom(LabelBasedNodeTypePresationStrategy.java:136)在org.springframework.data.neo4j.support.typerepresentation.LabelBasedNodeTypePresationStrategy.readAliasfrom(org.springframework.data.neo4j.support.mapping.TRSTypeAliasAccessor.readAliasfrom(TRSTypeAliasAccessor.java:36)org.springframework.data.neo4j.support.mapping.TRSTypeAliasAccessor.readAliasfrom(TRSTypeAliasAccessor.java:26)org.springframework.data.convert.DefaultTypeMapper.read类型(DefaultTypeMapper.java:102)在org.springframework.data.convert.DefaultTypeMapper.getDefaultedTypeToBeuse(DefaultTypeMapper.java:165)在org.springframework.data.convert.DefaultTypeMapper. readType(DefaultTypeMapper. java: 142)在org. springframework. data. neo4j. support. map。Neo4jEntityConverterImp. read(Neo4jEntityConverterInp. java: 77)在org. springframework. data. neo4j. support.映射。在org. springframework. data. neo4j. support.映射中读取(Neo4jEntityPersis. java: 170)$CachedConver. read。在org. springframework. data. neo4j. support上创建EntityFromState(Neo4jEntityPersi. java: 189)。Neo4jTemplate. createEntityFromState(Neo4jTemplate. java: 224)

你能看看课程,让我知道我在哪里做错了什么吗?

这是存储库类

public interface PersonRepository extends GraphRepository<Person>, CypherDslRepository<Person> {
String PERSONS_WITH_SEVERAL_ACME_IDENTITY = "MATCH (p:Person)-[r:HAS_LOGIN]->(a:AcmeIdp) " +
        "SET p:_Person, a:_AcmeIdp "+
        "WITH p, count(p) AS numoutgoing " +
        "WHERE numoutgoing > 1 " +
        "MATCH (p:Person)-[r:HAS_LOGIN]->(a:AcmeIdp) " +
        "SET p:_Person, a:_AcmeIdp "+
        "RETURN p";

Iterable<Person> findByFirstNameAndLastName(@NonNull final String firstName,@NonNull final String lastName);

Page<Person> findByFirstNameLike(@NonNull final String firstName,@NonNull final Pageable pageable);

@Query(PERSONS_WITH_SEVERAL_ACME_IDENTITY)
Page<Person> findOnesWithSeveralAcmeIdentities(@NonNull final Pageable pageable); }

person实体类

import com.example.analytics.model.AbstractEntity;
import com.example.analytics.model.relationship.Login;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.neo4j.graphdb.Direction;
import org.springframework.data.neo4j.annotation.*;

import java.time.LocalDateTime;
import java.util.Set;

@NodeEntity(useShortNames = true)
public class Person extends AbstractEntity {

    @GraphProperty(propertyName = "title", defaultValue = "")
    private String title;

    @GraphProperty(propertyName = "firstName", defaultValue = "")
    private String firstName;

    @GraphProperty(propertyName = "lastName", defaultValue = "")
    private String lastName;

    @GraphProperty(propertyName = "dateOfBirth", propertyType = String.class)
    private LocalDateTime dateOfBirth;

    @RelatedTo(type = "HAS_LOGIN", direction = Direction.OUTGOING, elementClass = AcmeIdentity.class)
    private Set<Login> logins;

    public String getTitle() {
        return title;
    }

    public void setTitle(final String title) {
        this.title = title;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(final String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(final String lastName) {
        this.lastName = lastName;
    }

    public LocalDateTime getDateOfBirth() {
        return dateOfBirth;
    }

    public void setDateOfBirth(final LocalDateTime dateOfBirth) {
        this.dateOfBirth = dateOfBirth;
    }

    public Set<Login> getLogins() {
        return logins;
    }

    public void setLogins(@NonNull final Set<Login> logins) {
        this.logins = logins;
    }
}

转换器

import org.checkerframework.checker.nullness.qual.NonNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Component
public class LocalDateTimeToStringConverter implements Converter<LocalDateTime, String> {

    private static final Logger LOG = LoggerFactory.getLogger(LocalDateTimeToStringConverter.class);

    @Value("${neo4j.dateTime.format:yyyy-MM-dd HH:mm:ss}")
    private String dateTimeFormat;

    @Override
    public String convert(@NonNull final LocalDateTime source) {
        LOG.debug("Converting LocalDateTime into String using the format: {}", dateTimeFormat);
        return String.valueOf(source.format(DateTimeFormatter.ofPattern(dateTimeFormat)));
    }

}

反向转换器

import org.checkerframework.checker.nullness.qual.NonNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Component
public class StringToLocalDateTimeConverter implements Converter<String, LocalDateTime> {

    private static final Logger LOG = LoggerFactory.getLogger(StringToLocalDateTimeConverter.class);

    @Value("${neo4j.dateTime.format:yyyy-MM-dd HH:mm:ss}")
    private String dateTimeFormat;

    /**
     * Convert the source of type S to target type T.
     *
     * @param source the source object to convert, which must be an instance of S (never {@code null})
     * @return the converted object, which must be an instance of T (potentially {@code null})
     * @throws IllegalArgumentException if the source could not be converted to the desired target type
     */
    @Override
    public LocalDateTime convert(@NonNull final String source) {
        LOG.debug("Converting String {} into LocalDateTime using the format: {}",source, dateTimeFormat);
        return LocalDateTime.parse(source, DateTimeFormatter.ofPattern(dateTimeFormat));
    }

}

主配置类

import com.example.analytics.converter.LocalDateTimeToStringConverter;
import com.example.analytics.converter.StringToLocalDateTimeConverter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.*;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.converter.ConverterRegistry;
import org.springframework.data.neo4j.config.Neo4jConfiguration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@Configuration
@EnableAutoConfiguration
@EnableTransactionManagement(mode = AdviceMode.PROXY)
@ComponentScan(basePackages = {"com.example.analytics"})
@PropertySource(value = "classpath:application.yml", ignoreResourceNotFound = false)
@Import({DatabaseConnectionConfiguration.class})
public class MainConfiguration extends Neo4jConfiguration {

    @Autowired
    private StringToLocalDateTimeConverter stringToLocalDateTimeConverter;

    @Autowired
    private LocalDateTimeToStringConverter localDateTimeToStringConverter;

    private static final Logger LOG = LoggerFactory.getLogger(MainConfiguration.class);

    public MainConfiguration() {
        setBasePackage("com.example.analytics.model");
    }

    @Bean
    public static PropertySourcesPlaceholderConfigurer propertyConfigIn() {
        return new PropertySourcesPlaceholderConfigurer();
    }

    @Bean
    @DependsOn({ "stringToLocalDateTimeConverter", "localDateTimeToStringConverter" })
    protected ConversionService neo4jConversionService() throws Exception {
        LOG.debug("Adding custom converters to conversion service ...");
        ConversionService conversionService = super.neo4jConversionService();
        ConverterRegistry registry = (ConverterRegistry) conversionService;
        registry.addConverter(stringToLocalDateTimeConverter);
        registry.addConverter(localDateTimeToStringConverter);
        LOG.debug("Addition of Converter from LocalDateTime to String and vice-versa has been completed!");
        return conversionService;
    }
}

使用存储库的服务片段

public Page<Person> findPersonsWithSeveralAcmeIdentitites(final Pageable pageable) {
    LOG.debug("Fetching persons with several ACME identities");

    if(pageable != null)
        return personRepository.findOnesWithSeveralAcmeIdentities(pageable);
   else 
        return personRepository.findOnesWithSeveralAcmeIdentities(getDefaultPageable());

}

共有1个答案

郝乐心
2023-03-14

然后,您必须遍历您的节点,并在每个节点上调用:

neo4jTemplate.postEntityCreation(node, MyEntity.class);

或者,这也应该起作用:

MATCH (n:User) set n:_User;

我认为你对Java8方法的引用过多了!!!只需使用普通的旧new。否则,您的代码将无法维护。

public static Pageable getDefaultPageable() {
    return new PageRequest(DEFAULT_PAGE_NUMBER, DEFAULT_PAGE_SIZE);
}
 类似资料:
  • 尝试在 工作,并将标签应用于创建的节点。 Q1.我可以告诉SDN只附加作为标签,并避免 Q2。如果没有,那么我如何将和标签附加到所有用户节点。目前只附加了标签 编辑: 问题1: 在我以前的SDN版本(即)中,突然查询开始工作,但在类似查询的存储库中失败,但适用于或 问题2: 当我更新我的SDN或Neo4j版本时,我得到了奇怪的异常,这就是为什么我没有更新我的SDN和Neo4j版本。 刚才我将SDN

  • 我正在尝试使用SDN3.0创建节点。2和Neo4j 2.0。1. 我是这样做的: 以这种方式执行,我得到for the

  • 在问这个问题之前,我提到了这个问题,但尽管看起来很相似,但这个问题并没有包含我的问题的答案。 我开发了Springboot项目,并在本地机器上创建了名为的docker映像。因此,当我运行时,它会列出我在本地拥有的所有图像, 然后我参考了这些文档,将我的docker图像拉到dockerhub中。所以我给图像加了标签,然后按照命令按下按钮, 但结果是一个错误, 推送引用存储库[docker.io/se

  • 问题内容: 谁能告诉我如何使用webdriver关闭除第一个标签/主标签之外的所有打开的标签? 我在下面尝试过,但是它同时关闭了所有标签,包括第一个标签。 请帮我。 问题答案: 获取所有窗口句柄,然后遍历它们,将webdriver切换到新的句柄,然后调用close方法。显然跳过原始手柄,然后切换回其余手柄。 就像是;

  • 我有一个库伯内特斯集群,其中有一个pod运行一个开放遥测收集器实例。 我的Kubernetes内部的Net app将跟踪导出到收集器实例,收集器实例又将跟踪导出到Elastic APM服务器。如果我将此配置(此处描述)用于我的收集器实例,则此配置将正常工作: 为了在Kubernetes中工作,我在ConfigMap中设置了此配置。这工作正常,但问题是这需要我在ConfigMap中添加一个我想要避免

  • 我正在尝试运行一个DynamoDB查询,该查询说我想要不以特定值开头的项目。我似乎找不到这样做的方法。 我尝试了以下4种评估方法,但都不管用。每一个都给我一个无效的运算符错误。 我已经尝试过的我的关键条件表达式如下所示: 如果删除not运算符,则会出现以下错误: KeyConditionExpressions每个键只能包含一个条件 在dynamodb中有这样做的方法吗?