spring-data-reference (arangodb)的@Ref是使用急切的还是懒惰的方式获取被引用对象?

问题描述 投票:1回答:1

我正在写一个模式,其中包括一些被引用的对象。我想知道实际的引用对象的获取是懒惰的还是急切的。

spring arangodb ref
1个回答
0
投票

截止到 arangodb-spring-data 3.2.5 引用对象的默认获取应该是急切的,正如你在 @Ref 注释类。

Ref.class

package com.arangodb.springframework.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.springframework.data.annotation.Reference;

/**
 * Annotation to indicate that the annotated field is stored as a document in
 * another collection instead of a nested document. The document {@literal _id}
 * of that document is stored as a reference in the stored field.
 *
 * @author Mark Vollmary
 *
 */
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.FIELD })
@Reference
public @interface Ref {

    /**
     * Whether the entity should be loaded lazily
     */
    boolean lazy() default false;

}

为了使引用的数据加载变得懒惰,你应该用以下方式来注释它

@Ref(lazy = true)
© www.soinside.com 2019 - 2024. All rights reserved.