glassfish
  1. glassfish
  2. GLASSFISH-1660

LAZY 1:N relationship: adding related entities without loading the whole collection

    Details

    • Type: New Feature New Feature
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 9.1pe
    • Fix Version/s: not determined
    • Component/s: entity-persistence
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

    • Issuezilla Id:
      1,660

      Description

      From forum: http://forums.java.net/jive/thread.jspa?forumID=56&threadID=20764

      In the current code, if I add a new entity to a lazily-loaded collection
      (OneToMany relationship), the whole collection is loaded from database.
      This is critical when we have many child entities in the collection.

      I think that there is no reason to load all child entities (in LAZY
      relationship) in order to insert just one entity.

      Here is my example (2 entities and a simple test):
      ///////////////

      @Entity
      public class ForumTopic {
      ...
      @OneToMany(mappedBy = "topic", fetch = FetchType.LAZY)
      private Collection<ForumPost> posts;
      ...
      }

      ///////////////

      @Entity
      public class ForumPost {
      ...
      @ManyToOne
      private ForumTopic topic;
      ...
      }

      ///////////////

      ForumPost post=new ForumPost();
      ForumTopic topic=em.find(...);
      Collection<ForumPost> postsInTopic=topic.getPosts();
      postsInTopic.add(post);
      post.setTopic(topic);
      ///////////////

      When "postsInTopic.add(post)" is being executed, I see that all posts in this
      topic are being fully loaded because Toplink Essentials shows the following log:

      SELECT ... FROM forum_post WHERE (topic_id = ?)

      I tested with glassfish-persistence-installer-v2-b26.jar, also the same behavior
      was with "v1" builds.

        Activity

        Hide
        jrengifo added a comment -
            • Issue 1660 has been confirmed by votes. ***
        Show
        jrengifo added a comment - Issue 1660 has been confirmed by votes. ***
        Hide
        mf125085 added a comment -

        Adding myself to interest list.

        Show
        mf125085 added a comment - Adding myself to interest list.
        Hide
        marina vatkina added a comment -

        resetting the default owner

        Show
        marina vatkina added a comment - resetting the default owner
        Hide
        Tom Mueller added a comment -

        Bulk change to set fix version to "not determined" where the issue is open but the value is for a released version.

        Show
        Tom Mueller added a comment - Bulk change to set fix version to "not determined" where the issue is open but the value is for a released version.

          People

          • Assignee:
            tware
            Reporter:
            vicnov
          • Votes:
            4 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated: