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 {
setCustomerId(odb.getCustomerID());
setOrderLineCount(odb.getOrderLineCount());
// For Atomicity Test 3
if( debugging )
debug.println(4, "Atomicity Test 3: OrderLineId: " +
getOrderLineCount());
setTotal(odb.getTotal().setScale(2, BigDecimal.ROUND_UP));
setEntryDate(new java.sql.Timestamp(new java.util.Date().getTime()));
Integer orderID = getId();
OrderLineEntLocal[] orderLines = new
OrderLineEntLocal[odb.getOrderLineCount()];
try {
Collection lines = this.getOrdLines();
ArrayList o_lines = odb.getOrderLines();
// now we have to add the order lines, and compute the total
for( int i = 0; i < odb.getOrderLineCount(); i++ ) {
OrderLineDataBean oldb = (OrderLineDataBean)o_lines.get(i);
int itemQuantity = oldb.getQuantity();
if(deferred){ // deferred order set status to 1 on all
orderLines[i] = orderLineHome.create(oldb.getO_line_num(),
orderID, oldb.getItemID(), itemQuantity, oldb.getTotalValue(), 1, null,
oldb.getMsrpAtPurchase());
}else if(itemQuantity > 20){ // set status to 1 on all large
order lines
orderLines[i] = orderLineHome.create(oldb.getO_line_num(),
orderID, oldb.getItemID(), itemQuantity, oldb.getTotalValue(), 1, null,
oldb.getMsrpAtPurchase());
}else{ // set status to 3 items have been purchased immediately
orderLines[i] = orderLineHome.create(oldb.getO_line_num(),
orderID, oldb.getItemID(), itemQuantity, oldb.getTotalValue(), 3, new
java.sql.Date(System.currentTimeMillis()), oldb.getMsrpAtPurchase());
}
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)
at
org.spec.jappserver.orders.orderlineent.ejb.OrderLineCmp20EJB$$EnhancerByCGLIB$$89145183.setOrderId(<generated>)
at
org.spec.jappserver.orders.orderlineent.ejb.OrderLineCmp20EJB.ejbCreate(OrderLineCmp20EJB.java:71)
at
org.spec.jappserver.orders.orderlineent.ejb.OrderLineCmp20EJB$$FastClassByCGLIB$$8e613403.invoke(<generated>)
at
org.openejb.entity.cmp.CMPCreateMethod.execute(CMPCreateMethod.java:148)
at
org.openejb.dispatch.DispatchInterceptor.invoke(DispatchInterceptor.java:72)
at
org.apache.geronimo.naming.java.ComponentContextInterceptor.invoke(ComponentContextInterceptor.java:56)
at
org.openejb.ConnectionTrackingInterceptor.invoke(ConnectionTrackingInterceptor.java:81)
at
org.openejb.entity.EntityInstanceInterceptor.invoke(EntityInstanceInterceptor.java:136)
at
org.openejb.entity.cmp.InTxCacheInterceptor.invoke(InTxCacheInterceptor.java:82)
at
org.openejb.transaction.ContainerPolicy$TxRequired.invoke(ContainerPolicy.java:119)
... 58 more
javax.ejb.TransactionRolledbackLocalException
at
org.openejb.transaction.ContainerPolicy$TxRequired.invoke(ContainerPolicy.java:123)
at
org.openejb.transaction.TransactionContextInterceptor.invoke(TransactionContextInterceptor.java:80)
at
org.openejb.SystemExceptionInterceptor.invoke(SystemExceptionInterceptor.java:82)
at org.openejb.GenericEJBContainer.invoke(GenericEJBContainer.java:234)
at
org.openejb.proxy.EJBMethodInterceptor.intercept(EJBMethodInterceptor.java:129)
at
org.openejb.proxy.EntityEJBLocalHome$$EnhancerByCGLIB$$6c6a9055.create(<generated>)
at
org.spec.jappserver.orders.orderent.ejb.OrderCmp20EJB.ejbPostCreate(OrderCmp20EJB.java:171)
at
org.spec.jappserver.orders.orderent.ejb.OrderCmp20EJB$$FastClassByCGLIB$$16ba8663.invoke(<generated>)
at
org.openejb.entity.cmp.CMPCreateMethod.execute(CMPCreateMethod.java:212)
at
org.openejb.dispatch.DispatchInterceptor.invoke(DispatchInterceptor.java:72)
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.
Here is the relevant deployment info:
<ejb-relation>
<ejb-relation-name>OrderEnt-OrderLineEnt</ejb-relation-name>
<ejb-relationship-role>
<ejb-relationship-role-name>OrderEnt</ejb-relationship-role-name>
<relationship-role-source>
<ejb-name>OrderEnt</ejb-name>
</relationship-role-source>
<cmr-field>
<cmr-field-name>ordLines</cmr-field-name>
</cmr-field>
<role-mapping>
<cmr-field-mapping>
<key-column>O_ID</key-column>
<foreign-key-column>OL_O_ID</foreign-key-column>
</cmr-field-mapping>
</role-mapping>
</ejb-relationship-role>
</ejb-relation>
</relationships>
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.
Cheers,
- Matt