Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] OneToMany <-> ManyToOne relationship


I am developing an EJB 3.0 web app on Oracle WebLogic Server 11gR1 PatchSet 1, and I am having problems
on update/delete with the relationship.

I have an entity Customer with two children DiscountCode an MicroMarket. The relation is many Customer has
one DiscountCode and many Customer has one MicroMarket. On the other direction it leaves as one DiscountCode
has many Customer and one MicroMarket has many Customer.

This is my code snippet,

public class Customer implements Serializable {  
    private static final long serialVersionUID = 1L;  
    private long customerId;  
    private String addressline1;  
    private String addressline2;  
    private String city;  
    private BigDecimal creditLimit;  
    private String email;  
    private String fax;  
    private String name;  
    private String phone;  
    private String state;  
    //bi-directional many-to-one association to DiscountCode  
    private DiscountCode discountCodeBean;  
    //bi-directional many-to-one association to MicroMarket  
    private MicroMarket microMarket;  
public class MicroMarket implements Serializable {  
    private static final long serialVersionUID = 1L;  
    private String zipCode;  
    private BigDecimal areaLength;    
    private BigDecimal areaWidth;  
    private BigDecimal radius;  
    //bi-directional many-to-one association to Customer  
    @OneToMany(mappedBy="microMarket", cascade=CascadeType.ALL)  
    private List<Customer> customers;  
The problem I am having is when I update the MicroMarket.zipCode in a Customer I get another record of
MicroMarket instead of the updated MicroMarket.

On deletion a Customer it does not delete the MicroMarket.
Well, I work only with Customer. So what I would like is when I delete a Customer
just only the MicroMarket child would be deleted.

The problem I have is that MicroMarket child is not deleted. That is wrong.

On the other hand the table corresponding to the DiscountCode entity must
leaves as it is without no update, no insert and no delete.


Back to the top