I have the problem too. I use unidirectional one-to-many associations with join tables:
Code:
@Entity
@Name("order")
public class Order implements Serializable {
private Set<OrderItem> orderItems;
@OneToMany(cascade = CascadeType.ALL)
@JoinTable(
name = "ORDER_ITEM",
joinColumns = @JoinColumn(name = "ORDER_ID"),
inverseJoinColumns = @JoinColumn(name = "ITEM_ID")
)
public Set<OrderItem> getOrderItems() {
return orderItems;
}
}
@Entity
@Name("orderItem")
public class OrderItem implements Serializable {
}
1). When I created two new item1 and item2, and save them to new order and run em.persist(order), the order1 and two items were saved to join table (order_item), item entity table, order entity table. (correct).
2). When I tried to delete the order1 and run em.remove(order), the order1, item1 and item2 were deleted from joint table (order_item) and order,item entity tables (correct).
3). I repeated step 1 to create order1, item1 and item2. Then I tried to remove item2 from order1, and add a new item3 to order1, then I run em.merge(order1), the result was that item1 still exists in item table and order_item table (correct), new item3 were added to item table and order_item join table (correct), item2 were deleted from order_order joit table, but item2 still existed in item entity table. (incorrect). It should be deleted.
I don't know whether it is bug or not. Thank you.