Uploaded image for project: 'Geronimo'
  1. Geronimo
  2. GERONIMO-675

CMR / CMP Fields should not be read-only

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.0-M4
    • 1.0-M5
    • OpenEJB
    • None
    • Windows

    Description

      > On 14/06/2005 12:42 PM, Matt Hogstrom wrote:
      >
      >>I have a typical bean sequence where there is an Order and a number of Order Lines. (1 ... many) The OrderEnt is created from a Session bean coincidentally named OrderSes. The OrderEnt then in ejbPostCreate creates the appropriate OrderLines. Here is the code from OrderEnt:
      >>
      >> public void ejbPostCreate(OrderDataBean odb, boolean deferred)
      >> throws CreateException {
      >>
      >>
      > <snip>
      >
      >>Depending on the situation one of the above orderLineHome.create methods is invoked. So far, so good.
      >>
      >>In the OrderLineEnt.create method things go a bit wrong. Here is the stack trace:
      >>
      >>Caused by: javax.ejb.EJBException: cmp-field [orderId] is read-only.
      >> at org.tranql.ejb.ReadOnlyCMPFieldAccessor.set(ReadOnlyCMPFieldAccessor.java:44)
      >> at org.openejb.entity.cmp.CMPSetter.invokeInstance(CMPSetter.java:74)
      >> at org.openejb.entity.cmp.CMPMethodInterceptor.intercept(CMPMethodInterceptor.java:75)
      >>
      >>
      > Based on this stack-trace, I confirm that the CMP field orderId is
      > mapped to a foreign key.
      >
      >>Here is the ejbCreate method that is failing
      >>
      >> public OrderLineEntPK ejbCreate(int id, Integer orderId, String itemId, int quantity, BigDecimal totalValue,
      >> int olineStatus, java.sql.Date shipDate, BigDecimal msrp) throws CreateException {
      >>
      >> if( debugging )
      >> debug.println(3, "ejbCreate of ol_id = " + id + ", o_id = "
      >> + orderId);
      >>
      >> setId(id);
      >> setOrderId(orderId); <==================== This is the line that is failing.
      >> setItemId(itemId);
      >> setQuantity(quantity);
      >> setTotalValue(totalValue.setScale(2, BigDecimal.ROUND_UP));
      >> setOlineStatus(olineStatus);
      >>
      >>
      >>
      >>OrderId is the FK to the Order.
      >>
      >>
      > Fields mapped to foreign key columns are read-only. They are read-only
      > for the following reason:
      > Let's assume that:
      > * we have one existing line item lineItemEntity;
      > * lineItemEntity is already related to an order orderEntity;
      > * orderEntity is related to two line items, lineItemEntity (as expected)
      > and lineItemEntity2;
      > * we want to relate lineItemEntity to a new order orderEntity2;
      > * orderEntity2 is related to zero line items; and
      > * line item defines a CMR field order to set its related order.
      >
      > In this specific scenario, if we set the CMR field order of
      > lineItemEntity to orderEntity2, then:
      > * orderEntity2 is now related to the line item lineItemEntity; and
      > * orderEntity is now related to only one line item lineItemEntity2.
      >
      > In this same scenario, if we set the CMP field orderId of lineItemEntity
      > to the primary key of orderEntity2, then I am not sure of what the
      > result should be. Indeed, it is a CMP field and no specfic semantic is
      > attached to it.
      >
      > To some extent, I am not sure that we should allow developers to update
      > relationships via a direct update to the underlying foreign key columns.
      > We could implement a fix to have a CMR semantic for CMP fields mapped to
      > foreign ley columns; yet it does not sound good. Having said that, I do
      > not have a strong opinion and I am happy to support such a scenario, if
      > we need to.
      >
      > Also, it is worth to notice that such a potential fix will only be able
      > to handle CMP having simple primary keys. CMP having compound primary
      > keys will still have a read-only approach.
      >
      >>First question is the deployment right for this scenario? If it is, then I think that the container is not acting correctly. This code runs on WebLogic, Sun One, WebSphere, etc.
      >>
      >>
      > Do you know if they properly support such scenarii (the CMP field must
      > have a CMR semantic)? Also, do you know if they do not allow such
      > scenarii in the case of compound PK CMP?
      >
      > Thanks,
      > Gianny

      Attachments

        Activity

          People

            gianny Gianny Damour
            hogstrom Matt Richard Hogstrom
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: