1. glassfish
  2. GLASSFISH-3516

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


    • 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:
    • Environment:

      Operating System: All
      Platform: All

    • Issuezilla Id:
    • Status Whiteboard:




      (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(
      at test.jpa.TestJPA.testBug(
      at test.jpa.TestJPA.main(

      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

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

      insert into orders
      values (1);

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


      2. Here's the Order entity:

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

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

      public Order() {

      public Long getId()

      { return id; }

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

      3. Here's the OrderItem entity:

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

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

      @JoinColumn(name = "ORDER_ID1", referencedColumnName = "ID")
      private Order order1;

      @JoinColumn(name = "ORDER_ID2", referencedColumnName = "ID")
      private Order order2;

      public OrderItem() {

      public Long getId() { return id; }

      public void setId(Long 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.


        No work has yet been logged on this issue.


          • Assignee:
          • Votes:
            7 Vote for this issue
            0 Start watching this issue


            • Created: