glassfish
  1. glassfish
  2. GLASSFISH-892

persistence of many-many relationship incorrect

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Cannot Reproduce
    • Affects Version/s: 9.0pe
    • Fix Version/s: 9.0pe
    • Component/s: entity-persistence
    • Labels:
      None
    • Environment:

      Operating System: Solaris
      Platform: Sun

    • Issuezilla Id:
      892

      Description

      I have an item/category many-to-many relationship. In Glassfish V2b10, the
      entity manager is reversing the keys such that the item_id is getting the
      category's id, and the category_id is getting the item's id.

      From Item.java:

      @ManyToMany(fetch=FetchType.LAZY)

      @JoinTable(name="ITEM_CATEGORY",inverseJoinColumns=

      {@JoinColumn(name="ITEM_ID")},
      joinColumns={@JoinColumn(name="CAT_ID")} )
      public Set<Category> getCategories() { return categories; }

      From Category.java:

      @ManyToMany(fetch=FetchType.LAZY)

      @JoinTable(name="ITEM_CATEGORY",inverseJoinColumns={@JoinColumn(name="ITEM_ID")}

      ,
      joinColumns=

      {@JoinColumn(name="CAT_ID")}

      )
      public Set<Category> getCategories()

      { return categories; }

        Activity

        Hide
        mf125085 added a comment -

        Could you please add the field definition for Category#items? It looks
        like your mapping should be:

        From Item.java:

        @ManyToMany(fetch=FetchType.LAZY, mappedBy="items")

        @JoinTable(name="ITEM_CATEGORY",inverseJoinColumns=

        {@JoinColumn(name="ITEM_ID")},
        joinColumns={@JoinColumn(name="CAT_ID")} )
        public Set<Category> getCategories() { return categories; }

        From Category.java:

        @ManyToMany(fetch=FetchType.LAZY)

        @JoinTable(name="ITEM_CATEGORY",inverseJoinColumns={@JoinColumn(name="ITEM_ID")}

        ,
        joinColumns=

        {@JoinColumn(name="CAT_ID")}

        )
        public Set<Item> getItems()

        { return items; }

        Please note, that the relationship is owned by Category. From
        the JPA (EJB3 persistence) spec, 9.1.25:

        JoinColumn[] joinColumns (Optional) The foreign key columns of the
        join table which reference the primary table of the entity owning the
        association (i.e. the owning side of the association).

        Show
        mf125085 added a comment - Could you please add the field definition for Category#items? It looks like your mapping should be: From Item.java: @ManyToMany(fetch=FetchType.LAZY, mappedBy="items") @JoinTable(name="ITEM_CATEGORY",inverseJoinColumns= {@JoinColumn(name="ITEM_ID")}, joinColumns={@JoinColumn(name="CAT_ID")} ) public Set<Category> getCategories() { return categories; } From Category.java: @ManyToMany(fetch=FetchType.LAZY) @JoinTable(name="ITEM_CATEGORY",inverseJoinColumns={@JoinColumn(name="ITEM_ID")} , joinColumns= {@JoinColumn(name="CAT_ID")} ) public Set<Item> getItems() { return items; } Please note, that the relationship is owned by Category . From the JPA (EJB3 persistence) spec, 9.1.25: JoinColumn[] joinColumns (Optional) The foreign key columns of the join table which reference the primary table of the entity owning the association (i.e. the owning side of the association).
        Hide
        marina vatkina added a comment -

        Reassigned

        Show
        marina vatkina added a comment - Reassigned
        Hide
        mf125085 added a comment -

        Situation works for me. We don't know, how the mapping was defined on the
        "Cagegory" side. Since we haven't heard back from the submitter, I'm closing
        this issue as not reproducable.

        Show
        mf125085 added a comment - Situation works for me. We don't know, how the mapping was defined on the "Cagegory" side. Since we haven't heard back from the submitter, I'm closing this issue as not reproducable.

          People

          • Assignee:
            mf125085
            Reporter:
            epesh
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: