spring-data-reference(arangodb)的@Ref是使用被引用对象的主动获取还是被动获取?

p5cysglq  于 2022-12-09  发布在  Go
关注(0)|答案(1)|浏览(121)

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

92dk7w1h

92dk7w1h1#

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)

相关问题