users@glassfish.java.net

RE: topLink, bean managed transaction, cascadeType.ALL

From: Gordon Yorke <gordon.yorke_at_oracle.com>
Date: Tue, 15 May 2007 11:23:30 -0400

Hello,
    The JPA specification has no concept of private ownership or orphan removal and does not support relationship maintenance. You could use custom TopLink APIs to configure the relationship for "private ownership" but within the confines of the JPA specification your will have to delete the SupplierPriceLists within your code.
    In the example you are testing are you sure that there are SupplierPriceLists within the SupplierContracts? Although you would not see deletes I would expect there to be updates to the relation table that backs this relationship. Also please note that at the end of your edit() method there is no need to call merge as you are working within the persistence context already.

--Gordon


  -----Original Message-----
  From: Hilmi Hilmiev [mailto:hhilmiev_at_gmail.com]
  Sent: Tuesday, May 15, 2007 9:38 AM
  To: users_at_glassfish.dev.java.net
  Subject: topLink, bean managed transaction, cascadeType.ALL


  Hello all,

  I have following case:

  //Entity
  public class SupplierPriceLists implements Serializable {
      @Id
      @Column(name = "ArtID", nullable = false)
      @GeneratedValue(strategy=GenerationType.IDENTITY )
      private Integer artID;
  }

  //Entity
  public class SupplierContracts implements Serializable {
       @Id
       @Column(name = "ContractID", nullable = false)
       @GeneratedValue(strategy= GenerationType.IDENTITY)
       private Integer contractID;

       @OneToMany(cascade = {CascadeType.ALL}, mappedBy = "contractID", fetch=FetchType.EAGER)
       private Collection<SupplierPriceLists> supplierPriceListsCollection;
  }

  //Facade
  public void edit( SupplierContracts supplierContracts ){
      SupplierContracts supplierContractsNew = (SupplierContracts) em.find(SupplierContracts.class, supplierContracts.getContractID());
      List<SupplierPriceLists> lSupplierPriceLists = new ArrayList<SupplierPriceLists>();
      supplierContractsNew.setSupplierPriceListsCollection(lSupplierPriceLists);
      supplierContractsNew.setLastChangeDate(new Date());
      supplierContractsNew = em.merge(supplierContractsNew);
  }

  Result from topLink logging
  UPDATE SupplierContracts SET LastChangeDate = ? WHERE (ContractID = ?)

  How to delete all SupplierPriceLists items from SupplierContracts?
  What is wrong to get delete query produced from
  List<SupplierPriceLists> lSupplierPriceLists = new ArrayList<SupplierPriceLists>();
  supplierContractsNew.setSupplierPriceListsCollection(lSupplierPriceLists);

  What i miss? Any subject on possible bug, anything in category "known issues"?

  Server: SunOne AS PE 9

  Thanks in advance to all your attentions!