users@glassfish.java.net

Re: [JPA] BUG in the class weaver

From: <glassfish_at_javadesktop.org>
Date: Wed, 15 Aug 2007 11:54:44 PDT

The 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 much, but that's not the point. It took my quite a while to reduce my large business case to this little thing.

[b]1. Here's how to create and populate the tables:[/b]

[pre]
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;
[/pre]


[b]2. Here's the Order entity:[/b]

[pre]
@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;
    }
}
[/pre]


[b]3. Here's the OrderItem entity:[/b]

[pre]
@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;
    }
}
[/pre]


[b]4. And finally, here's how to produce the bug:[/b]

[pre]
        public void runBug() {
                OrderItem oi = em.find(OrderItem.class, 1L);
                System.out.println(oi.getOrder1().getId());
        }
[/pre]


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

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

Best regards,
Bisser
[Message sent by forum member 'vesuvius' (vesuvius)]

http://forums.java.net/jive/thread.jspa?messageID=231005