3 Replies Latest reply on Apr 11, 2006 4:44 AM by Alexander Hartner

    Force Lazy Fetch on One-Many

    Alexander Hartner Expert

      I have the following OneToMany relationship annotated as shown here.

       @OneToMany(fetch = FetchType.LAZY)
       public Collection<Parameter> getParameters()
       {
       return parameters;
       }
       public void setParameters(Collection<Parameter> parameters)
       {
       this.parameters = parameters;
       }
      


      As soon as the object is fetched all contained objects (Parameters) are also fetched even though they are annotated as lazy. I know the spec suggests the default behaviour for a OneToMany should be EAGER. I would still like to disable this and load the contained objects LAZY. The reason for this is that the contained objects include a BLOB, which has a significant penalty.

      I implemented a "hack" of a work around by changing it to a ManyToMany and add a @Transient method to return the map it onto a OneToMany. This is rather poor, so if you have a better suggestion I would like to hear it.