首页 > 解决方案 > spring-data-reference (arangodb) 的 @Ref 是否使用了对引用对象的渴望或延迟获取?

问题描述

我正在编写一个包含一些引用对象的模式。我试图了解引用对象的实际获取是惰性的还是急切的。

标签: springarangodbref

解决方案


正如您在注释类arangodb-spring-data 3.2.5中看到的那样,引用对象的默认获取应该是急切的。@Ref

参考类

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)

推荐阅读