Search code examples
springarangodbref

Is @Ref of spring-data-reference (arangodb) uses eager or lazy fetching of the referenced object?


I'm writing a schema which includes some referenced objects. I'm trying to understand whether the actual fetching of the referenced object is lazy or eager.


Solution

  • As of arangodb-spring-data 3.2.5 the default fetch of referenced objects should be eager, as you can see in the @Ref annotation class.

    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;
    
    }
    

    To make the referenced data loading lazy you should annotate it with

    @Ref(lazy = true)