glassfish
  1. glassfish
  2. GLASSFISH-3516

Two @ManyToOne to one and the same entity class fail, if one is EAGER and the other is LAZY

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: 9.0pe
    • Fix Version/s: not determined
    • Component/s: entity-persistence
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

    • Issuezilla Id:
      3,516
    • Status Whiteboard:
      Hide

      HIGH

      Show
      HIGH

      Description

      (You can find a Test Case to reproduce the bug at the bottom...)

      I'm getting errors like this:

      Exception in thread "Main Thread" java.lang.NoSuchMethodError: _toplink_getorder1
      at test.jpa.entities.OrderItem.getOrder1(OrderItem.java:49)
      at test.jpa.TestJPA.testBug(TestJPA.java:845)
      at test.jpa.TestJPA.main(TestJPA.java:874)

      when there are two @ManyToOne relationships to one and the same Entity class and
      one of them is EAGER, while the other is LAZY.

      The bug is verified on GlassFish Release Candidate 2: Oracle TopLink Essentials

      • 2.0 (Build b58a-rc2 (08/09/2007)).
        Furthermore, TopLink 11g Preview doesn't throw NoSuchMethodError, but instead
        the EAGER relationship is ALWAYS null, while the LAZY one is fetched properly.

      ---------------------------
      Test Case:
      ---------------------------

      I have tried to reduce everything to the bare minimum, so that the bug will
      appear without too much clutter around it. Admittedly, this TEST CASE doesn't do
      anything useful, but that's not the point. It took my quite a while to reduce my
      large business case to this little thing.

      1. Here's how to create and populate the tables:

      create table orders
      (id number(18,0) not null);

      alter table orders
      add constraint orders_pk primary key (id);

      create table order_items
      (order_item_id number(18,0) not null,
      order_id1 number(18,0) not null,
      order_id2 number(18,0) not null);

      alter table order_items
      add constraint order_items_pk primary key (order_item_id);

      alter table order_items
      add constraint order_items_order1_fk foreign key (order_id1) references orders
      (id);

      alter table order_items
      add constraint order_items_order2_fk foreign key (order_id2) references orders
      (id);

      insert into orders
      values (1);

      insert into order_items
      values (1, 1, 1);

      commit;

      2. Here's the Order entity:

      @Entity
      @Table(name = "ORDERS")
      public class Order implements Serializable {

      @Id
      @Column(name = "ID", nullable = false)
      private Long id;

      public Order() {
      }

      public Long getId()

      { return id; }

      public void setId(Long id) { this.id = id; }
      }



      3. Here's the OrderItem entity:


      @Entity
      @Table(name = "ORDER_ITEMS")
      public class OrderItem implements Serializable {

      @Id
      @Column(name="ORDER_ITEM_ID", nullable = false)
      private Long id;

      @ManyToOne(fetch=FetchType.EAGER)
      @JoinColumn(name = "ORDER_ID1", referencedColumnName = "ID")
      private Order order1;

      @ManyToOne(fetch=FetchType.LAZY)
      @JoinColumn(name = "ORDER_ID2", referencedColumnName = "ID")
      private Order order2;

      public OrderItem() {
      }

      public Long getId() { return id; }

      public void setId(Long id)

      { this.id = id; }

      public Order getOrder1()

      { return order1; }

      public void setOrder1(Order order)

      { this.order1 = order; }

      public Order getOrder2()

      { return order2; }

      public void setOrder2(Order order)

      { this.order2 = order; }

      }

      4. And finally, here's how to produce the bug:

      public void testBug()

      { OrderItem oi = em.find(OrderItem.class, 1L); System.out.println(oi.getOrder1().getId()); }

      You'll see the stack trace that I published above.

      I have not added a persistence.xml. It's a straightforward task to create one.

        Activity

        Hide
        gfbugbridge added a comment -

        <BT6595640>

        Show
        gfbugbridge added a comment - <BT6595640>
        Hide
        pkrogh added a comment -

        A workaround of setting both mappings to either be LAZY or EAGER has been
        suggested in the bug. Downgrading this issue to a P4 HIGH.

        Show
        pkrogh added a comment - A workaround of setting both mappings to either be LAZY or EAGER has been suggested in the bug. Downgrading this issue to a P4 HIGH.
        Hide
        sproket added a comment -
            • Issue 3516 has been confirmed by votes. ***
        Show
        sproket added a comment - Issue 3516 has been confirmed by votes. ***
        Hide
        nsn added a comment -

        Created an attachment (id=1605)
        Example entities

        Show
        nsn added a comment - Created an attachment (id=1605) Example entities
        Hide
        tware added a comment -
            • Issue 5393 has been marked as a duplicate of this issue. ***
        Show
        tware added a comment - Issue 5393 has been marked as a duplicate of this issue. ***
        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:
            bisser
          • Votes:
            7 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: