0 Replies Latest reply on Dec 12, 2007 11:40 PM by vineetvishal

    javax.ejb.EJBException: Update failed. Expected one affected

    vineetvishal

      Hi, I'm facing problem with thisissue since 10 days, Please help.

      It comes out of the method properly but after it runs the ejbStore(), it throws an error while updating one of the table.

      2007-11-29 15:52:55,593 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreEntityCommand.au.com.cams.cims.ar.ejb.Charge] Executing SQL: UPDATE arinpchg SET modified_date=?, doc_num=?, printing_status=? WHERE trx_num=?
      2007-11-29 15:52:55,593 TRACE [org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMP1xFieldBridge.au.com.cams.cims.ar.ejb.Charge#modifiedDate] param: i=1, type=TIMESTAMP, value=2007-11-29 15:52:53.14
      2007-11-29 15:52:55,593 TRACE [org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMP1xFieldBridge.au.com.cams.cims.ar.ejb.Charge#docNum] param: i=2, type=VARCHAR, value=INV297217
      2007-11-29 15:52:55,593 TRACE [org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMP1xFieldBridge.au.com.cams.cims.ar.ejb.Charge#printingStatus] param: i=3, type=INTEGER, value=1
      2007-11-29 15:52:55,593 TRACE [org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMP1xFieldBridge.au.com.cams.cims.ar.ejb.Charge#trxNum] param: i=4, type=VARCHAR, value=ARTRX395716
      2007-11-29 15:52:55,734 ERROR [org.jboss.ejb.plugins.LogInterceptor] TransactionRolledbackException in method: public abstract au.com.cams.cims.ar.data.PendingChargeResponse au.com.cams.cims.business.ejb.PendingChargeManager.processPendingCharges(au.com.cams.cims.ar.data.PendingChargeRequest,au.com.cams.cims.core.data.DUser) throws au.com.cams.cims.core.util.StoredProcedureFailedException,au.com.cams.cims.core.util.UpdateFailedException,java.rmi.RemoteException, causedBy:
      org.jboss.tm.JBossRollbackException: Unable to commit, tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=MEL-LAP-XP-66/59, BranchQual=, localId=59] status=STATUS_NO_TRANSACTION; - nested throwable: (javax.ejb.EJBException: Update failed. Expected one affected row: rowsAffected=0, id=au.com.cams.cims.ar.data.ChargePK@839418b6)
      at org.jboss.tm.TransactionImpl.commit(TransactionImpl.java:372)
      at org.jboss.ejb.plugins.TxInterceptorCMT.endTransaction(TxInterceptorCMT.java:501)
      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:361)
      at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:181)
      at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:168)
      at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:205)
      at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:136)
      at org.jboss.ejb.SessionContainer.internalInvoke(SessionContainer.java:648)
      at org.jboss.ejb.Container.invoke(Container.java:954)
      at sun.reflect.GeneratedMethodAccessor108.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:585)
      at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
      at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
      at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
      at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
      at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
      at org.jboss.invocation.local.LocalInvoker$MBeanServerAction.invoke(LocalInvoker.java:169)
      at org.jboss.invocation.local.LocalInvoker.invoke(LocalInvoker.java:118)
      at org.jboss.invocation.InvokerInterceptor.invokeLocal(InvokerInterceptor.java:209)
      at org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.java:195)
      at org.jboss.proxy.TransactionInterceptor.invoke(TransactionInterceptor.java:61)
      at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:70)
      at org.jboss.proxy.ejb.StatelessSessionInterceptor.invoke(StatelessSessionInterceptor.java:112)
      at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:100)
      at $Proxy508.processPendingCharges(Unknown Source)
      at au.com.cams.cims.ar.cmd.PendingChargeManagerCmdBean.doProcessPendingCharges(Unknown Source)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:585)
      at au.com.cams.cims.core.cmd.AbstractCmdBean.execute(Unknown Source)
      at au.com.cams.cims.core.sys.CIMSCommandBeanManager.doCommandBeanExecute(Unknown Source)
      at au.com.cams.cims.core.sys.CIMSCommandBeanManager.execute(Unknown Source)
      at au.com.singtech.saf.MainServlet.doPost(Unknown Source)
      at au.com.singtech.saf.MainServlet.doGet(Unknown Source)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
      at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
      at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
      at org.jboss.web.tomcat.tc5.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
      at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
      at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
      at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
      at java.lang.Thread.run(Thread.java:595)
      Caused by: javax.ejb.EJBException: Update failed. Expected one affected row: rowsAffected=0, id=au.com.cams.cims.ar.data.ChargePK@839418b6
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreEntityCommand.execute(JDBCStoreEntityCommand.java:169)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.storeEntity(JDBCStoreManager.java:666)
      at org.jboss.ejb.plugins.CMPPersistenceManager.storeEntity(CMPPersistenceManager.java:428)
      at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.storeEntity(CachedConnectionInterceptor.java:273)
      at org.jboss.ejb.EntityContainer.storeEntity(EntityContainer.java:756)
      at org.jboss.ejb.GlobalTxEntityMap$2.synchronize(GlobalTxEntityMap.java:149)
      at org.jboss.ejb.GlobalTxEntityMap$GlobalTxSynchronization.synchronize(GlobalTxEntityMap.java:295)
      at org.jboss.ejb.GlobalTxEntityMap$GlobalTxSynchronization.beforeCompletion(GlobalTxEntityMap.java:345)
      at org.jboss.tm.TransactionImpl.doBeforeCompletion(TransactionImpl.java:1491)
      at org.jboss.tm.TransactionImpl.beforePrepare(TransactionImpl.java:1110)
      at org.jboss.tm.TransactionImpl.commit(TransactionImpl.java:324)
      ... 56 more
      2007-11-29 15:52:55,750 INFO [STDOUT] 15:52:55,750 ERROR [AbstractCmdBean] Action method for action 'processPendingCharges' threw an Exception: org.jboss.tm.JBossTransactionRolledbackException: null; nested exception is:
      org.jboss.tm.JBossRollbackException: Unable to commit, tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=MEL-LAP-XP-66/59, BranchQual=, localId=59] status=STATUS_NO_TRANSACTION; - nested throwable: (javax.ejb.EJBException: Update failed. Expected one affected row: rowsAffected=0, id=au.com.cams.cims.ar.data.ChargePK@839418b6); - nested throwable: (org.jboss.tm.JBossRollbackException: Unable to commit, tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=MEL-LAP-XP-66/59, BranchQual=, localId=59] status=STATUS_NO_TRANSACTION; - nested throwable: (javax.ejb.EJBException: Update failed. Expected one affected row: rowsAffected=0, id=au.com.cams.cims.ar.data.ChargePK@839418b6))
      2007-11-29 15:52:55,750 INFO [STDOUT] 195766 [http-0.0.0.0-8080-1] ERROR au.com.cams.cims.core.cmd.AbstractCmdBean 127.0.0.1 - Action method for action 'processPendingCharges' threw an Exception: org.jboss.tm.JBossTransactionRolledbackException: null; nested exception is:
      org.jboss.tm.JBossRollbackException: Unable to commit, tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=MEL-LAP-XP-66/59, BranchQual=, localId=59] status=STATUS_NO_TRANSACTION; - nested throwable: (javax.ejb.EJBException: Update failed. Expected one affected row: rowsAffected=0, id=au.com.cams.cims.ar.data.ChargePK@839418b6); - nested throwable: (org.jboss.tm.JBossRollbackException: Unable to commit, tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=MEL-LAP-XP-66/59, BranchQual=, localId=59] status=STATUS_NO_TRANSACTION; - nested throwable: (javax.ejb.EJBException: Update failed. Expected one affected row: rowsAffected=0, id=au.com.cams.cims.ar.data.ChargePK@839418b6))
      2007-11-29 15:52:55,750 INFO [STDOUT] 195766 [http-0.0.0.0-8080-1] DEBUG au.com.cams.cims.core.cmd.AbstractCmdBean 127.0.0.1 - org.jboss.tm.JBossTransactionRolledbackException: null; nested exception is:
      org.jboss.tm.JBossRollbackException: Unable to commit, tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=MEL-LAP-XP-66/59, BranchQual=, localId=59] status=STATUS_NO_TRANSACTION; - nested throwable: (javax.ejb.EJBException: Update failed. Expected one affected row: rowsAffected=0, id=au.com.cams.cims.ar.data.ChargePK@839418b6); - nested throwable: (org.jboss.tm.JBossRollbackException: Unable to commit, tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=MEL-LAP-XP-66/59, BranchQual=, localId=59] status=STATUS_NO_TRANSACTION; - nested throwable: (javax.ejb.EJBException: Update failed. Expected one affected row: rowsAffected=0, id=au.com.cams.cims.ar.data.ChargePK@839418b6))
      at org.jboss.ejb.plugins.TxInterceptorCMT.throwJBossException(TxInterceptorCMT.java:569)
      at org.jboss.ejb.plugins.TxInterceptorCMT.endTransaction(TxInterceptorCMT.java:506)
      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:361)
      at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:181)
      at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:168)
      at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:205)
      at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:136)
      at org.jboss.ejb.SessionContainer.internalInvoke(SessionContainer.java:648)
      at org.jboss.ejb.Container.invoke(Container.java:954)
      at sun.reflect.GeneratedMethodAccessor108.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:585)
      at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
      at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
      at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
      at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
      at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
      at org.jboss.invocation.local.LocalInvoker$MBeanServerAction.invoke(LocalInvoker.java:169)
      at org.jboss.invocation.local.LocalInvoker.invoke(LocalInvoker.java:118)
      at org.jboss.invocation.InvokerInterceptor.invokeLocal(InvokerInterceptor.java:209)
      at org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.java:195)
      at org.jboss.proxy.TransactionInterceptor.invoke(TransactionInterceptor.java:61)
      at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:70)
      at org.jboss.proxy.ejb.StatelessSessionInterceptor.invoke(StatelessSessionInterceptor.java:112)
      at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:100)
      at $Proxy508.processPendingCharges(Unknown Source)
      at au.com.cams.cims.ar.cmd.PendingChargeManagerCmdBean.doProcessPendingCharges(Unknown Source)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:585)
      at au.com.cams.cims.core.cmd.AbstractCmdBean.execute(Unknown Source)
      at au.com.cams.cims.core.sys.CIMSCommandBeanManager.doCommandBeanExecute(Unknown Source)
      at au.com.cams.cims.core.sys.CIMSCommandBeanManager.execute(Unknown Source)
      at au.com.singtech.saf.MainServlet.doPost(Unknown Source)
      at au.com.singtech.saf.MainServlet.doGet(Unknown Source)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
      at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
      at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
      at org.jboss.web.tomcat.tc5.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
      at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
      at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
      at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
      at java.lang.Thread.run(Thread.java:595)
      Caused by: org.jboss.tm.JBossRollbackException: Unable to commit, tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=MEL-LAP-XP-66/59, BranchQual=, localId=59] status=STATUS_NO_TRANSACTION; - nested throwable: (javax.ejb.EJBException: Update failed. Expected one affected row: rowsAffected=0, id=au.com.cams.cims.ar.data.ChargePK@839418b6)
      at org.jboss.tm.TransactionImpl.commit(TransactionImpl.java:372)
      at org.jboss.ejb.plugins.TxInterceptorCMT.endTransaction(TxInterceptorCMT.java:501)
      ... 55 more
      Caused by: javax.ejb.EJBException: Update failed. Expected one affected row: rowsAffected=0, id=au.com.cams.cims.ar.data.ChargePK@839418b6
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreEntityCommand.execute(JDBCStoreEntityCommand.java:169)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.storeEntity(JDBCStoreManager.java:666)
      at org.jboss.ejb.plugins.CMPPersistenceManager.storeEntity(CMPPersistenceManager.java:428)
      at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.storeEntity(CachedConnectionInterceptor.java:273)
      at org.jboss.ejb.EntityContainer.storeEntity(EntityContainer.java:756)
      at org.jboss.ejb.GlobalTxEntityMap$2.synchronize(GlobalTxEntityMap.java:149)
      at org.jboss.ejb.GlobalTxEntityMap$GlobalTxSynchronization.synchronize(GlobalTxEntityMap.java:295)
      at org.jboss.ejb.GlobalTxEntityMap$GlobalTxSynchronization.beforeCompletion(GlobalTxEntityMap.java:345)
      at org.jboss.tm.TransactionImpl.doBeforeCompletion(TransactionImpl.java:1491)
      at org.jboss.tm.TransactionImpl.beforePrepare(TransactionImpl.java:1110)
      at org.jboss.tm.TransactionImpl.commit(TransactionImpl.java:324)
      ... 56 more

      MY ENTITY BEAN IS:

      /*
      * Copyright 2000 by Sing Technologies Pty. Ltd.,
      * Level 11, 269 Wickham Street, Fortitude Valley, Qld 4006, Australia
      * All rights reserved.
      *
      * This software is the confidential and proprietary information
      * of Sing Technologies Pty. Ltd. ("Confidential Information"). You
      * shall not disclose such Confidential Information and shall use
      * it only in accordance with the terms of the license agreement
      * you entered into with Sing Technologies.
      */

      package au.com.cams.cims.ar.ejb;

      import java.sql.*;
      import javax.ejb.*;
      import au.com.cams.cims.ar.data.*;
      import au.com.cams.cims.core.data.*;
      import au.com.cams.cims.core.util.*;
      import au.com.cams.cims.core.ejb.*;
      import au.com.cams.cims.core.app.*;
      import org.apache.log4j.*;
      import javax.naming.*;
      import javax.rmi.*;
      import java.util.*;
      import java.rmi.RemoteException;

      /**
      * @stereotype EntityBean
      * @persistence Container
      * @homeInterface au.com.cams.cims.ar.ejb.ChargeHome
      * @remoteInterface au.com.cams.cims.ar.ejb.Charge
      * @primaryKey au.com.cams.cims.ar.ejb.ChargePK
      */
      public class ChargeBean implements EntityBean {
      static private Logger log = Logger.getLogger(ChargeBean.class.getName());
      private static final String datasource = "java:ds/cims";
      private static final String chargeLineRef = "java:comp/env/ejb/au.com.cams.cims.ar.ejb.ChargeLineHome";

      // Used by the isModified extension
      private transient boolean isDirty;
      public boolean isModified() {
      return isDirty;
      }

      /** @field Key VARCHAR(20) CIMSSchema.dbo.arinpchg.trx_num */
      public String trxNum;
      /** @field VARCHAR(20) CIMSSchema.dbo.arinpchg.apply_to_num */
      public String applyToNum;
      /** @field VARCHAR(20) CIMSSchema.dbo.arinpchg.terms_code */
      public String termsCode;
      /** @field VARCHAR(20) CIMSSchema.dbo.arinpchg.fin_chg_code */
      public String finChgCode;
      /** @field VARCHAR(20) CIMSSchema.dbo.arinpchg.shipping_code */
      public String shippingCode;
      /** @field VARCHAR(20) CIMSSchema.dbo.arinpchg.posting_code */
      public String postingCode;
      /** @field VARCHAR(20) CIMSSchema.dbo.arinpchg.tax_code */
      public String taxCode;
      /** @field TIMESTAMP(23) CIMSSchema.dbo.arinpchg.aging_date */
      public Timestamp agingDate;
      /** @field TIMESTAMP(23) CIMSSchema.dbo.arinpchg.due_date */
      public Timestamp dueDate;
      /** @field FLOAT(15) CIMSSchema.dbo.arinpchg.gross_amount */
      public Double grossAmount;
      /** @field FLOAT(15) CIMSSchema.dbo.arinpchg.tax_amount */
      public Double taxAmount;
      /** @field FLOAT(15) CIMSSchema.dbo.arinpchg.tax_included_amount */
      public Double taxIncludedAmount;
      /** @field FLOAT(15) CIMSSchema.dbo.arinpchg.freight_amount */
      public Double freightAmount;
      /** @field FLOAT(15) CIMSSchema.dbo.arinpchg.tax_on_freight_amount */
      public Double taxOnFreightAmount;
      /** @field FLOAT(15) CIMSSchema.dbo.arinpchg.net_amount */
      public Double netAmount;
      /** @field FLOAT(15) CIMSSchema.dbo.arinpchg.paid_amount */
      public Double paidAmount;
      /** @field FLOAT(15) CIMSSchema.dbo.arinpchg.due_amount */
      public Double dueAmount;
      /** @field INTEGER(10) CIMSSchema.dbo.arinpchg.trx_type */
      public Integer trxType;
      /** @field VARCHAR(20) CIMSSchema.dbo.arinpchg.doc_num */
      public String docNum;
      /** @field TIMESTAMP(23) CIMSSchema.dbo.arinpchg.doc_date */
      public Timestamp docDate;
      /** @field TIMESTAMP(23) CIMSSchema.dbo.arinpchg.apply_date */
      public Timestamp applyDate;
      /** @field VARCHAR(20) CIMSSchema.dbo.arinpchg.debtor_num */
      public String debtorNum;
      /** @field INTEGER(10) CIMSSchema.dbo.arinppyt.trx_status */
      public Integer trxStatus;
      /** @field INTEGER(10) CIMSSchema.dbo.arinppyt.approval_status */
      public Integer approvalStatus;
      /** @field INTEGER(10) CIMSSchema.dbo.arinpchg.printing_status */
      public Integer printingStatus;
      /** @field INTEGER(10) CIMSSchema.dbo.arinpchg.posting_status */
      public Integer postingStatus;
      /** @field INTEGER(10) CIMSSchema.dbo.arinpchg.hold_status */
      public Integer holdStatus;
      /** @field VARCHAR(50) CIMSSchema.dbo.arinpchg.hold_reason */
      public String holdReason;
      /** @field VARCHAR(2000) CIMSSchema.dbo.arinpchg.notes */
      public String notes;
      /** @field VARCHAR(200) CIMSSchema.dbo.arinpchg.message */
      public String message;
      /** @field INTEGER(10) CIMSSchema.dbo.arinpchg.next_sequence_id */
      public Integer nextSequenceId;
      /** @field VARCHAR(100) CIMSSchema.dbo.arinpchg.billing_addressee */
      public String billingAddressee;
      /** @field VARCHAR(50) CIMSSchema.dbo.arinpchg.billing_job_position */
      public String billingJobPosition;
      /** @field VARCHAR(50) CIMSSchema.dbo.arinpchg.billing_addr1 */
      public String billingAddr1;
      /** @field VARCHAR(50) CIMSSchema.dbo.arinpchg.billing_addr2 */
      public String billingAddr2;
      /** @field VARCHAR(50) CIMSSchema.dbo.arinpchg.billing_addr3 */
      public String billingAddr3;
      /** @field VARCHAR(50) CIMSSchema.dbo.arinpchg.billing_locality */
      public String billingLocality;
      /** @field VARCHAR(20) CIMSSchema.dbo.arinpchg.billing_state */
      public String billingState;
      /** @field VARCHAR(20) CIMSSchema.dbo.arinpchg.billing_postcode */
      public String billingPostcode;
      /** @field VARCHAR(20) CIMSSchema.dbo.arinpchg.billing_country */
      public String billingCountry;
      /** @field VARCHAR(30) CIMSSchema.dbo.arinpchg.billing_phone_home */
      public String billingPhoneHome;
      /** @field VARCHAR(30) CIMSSchema.dbo.arinpchg.billing_phone_business */
      public String billingPhoneBusiness;
      /** @field VARCHAR(30) CIMSSchema.dbo.arinpchg.billing_phone_mobile */
      public String billingPhoneMobile;
      /** @field VARCHAR(30) CIMSSchema.dbo.arinpchg.billing_phone_car */
      public String billingPhoneCar;
      /** @field VARCHAR(30) CIMSSchema.dbo.arinpchg.billing_fax_home */
      public String billingFaxHome;
      /** @field VARCHAR(30) CIMSSchema.dbo.arinpchg.billing_fax_business */
      public String billingFaxBusiness;
      /** @field VARCHAR(100) CIMSSchema.dbo.arinpchg.billing_email */
      public String billingEmail;
      /** @field VARCHAR(100) CIMSSchema.dbo.arinpchg.billing_email2 */
      public String billingEmail2;
      /** @field VARCHAR(100) CIMSSchema.dbo.arinpchg.billing_website */
      public String billingWebsite;
      /** @field VARCHAR(100) CIMSSchema.dbo.arinpchg.shipping_addressee */
      public String shippingAddressee;
      /** @field VARCHAR(50) CIMSSchema.dbo.arinpchg.shipping_job_position */
      public String shippingJobPosition;
      /** @field VARCHAR(50) CIMSSchema.dbo.arinpchg.shipping_addr1 */
      public String shippingAddr1;
      /** @field VARCHAR(50) CIMSSchema.dbo.arinpchg.shipping_addr2 */
      public String shippingAddr2;
      /** @field VARCHAR(50) CIMSSchema.dbo.arinpchg.shipping_addr3 */
      public String shippingAddr3;
      /** @field VARCHAR(50) CIMSSchema.dbo.arinpchg.shipping_locality */
      public String shippingLocality;
      /** @field VARCHAR(20) CIMSSchema.dbo.arinpchg.shipping_state */
      public String shippingState;
      /** @field VARCHAR(20) CIMSSchema.dbo.arinpchg.shipping_postcode */
      public String shippingPostcode;
      /** @field VARCHAR(20) CIMSSchema.dbo.arinpchg.shipping_country */
      public String shippingCountry;
      /** @field VARCHAR(30) CIMSSchema.dbo.arinpchg.shipping_phone_home */
      public String shippingPhoneHome;
      /** @field VARCHAR(30) CIMSSchema.dbo.arinpchg.shipping_phone_business */
      public String shippingPhoneBusiness;
      /** @field VARCHAR(30) CIMSSchema.dbo.arinpchg.shipping_phone_mobile */
      public String shippingPhoneMobile;
      /** @field VARCHAR(30) CIMSSchema.dbo.arinpchg.shipping_phone_car */
      public String shippingPhoneCar;
      /** @field VARCHAR(30) CIMSSchema.dbo.arinpchg.shipping_fax_home */
      public String shippingFaxHome;
      /** @field VARCHAR(30) CIMSSchema.dbo.arinpchg.shipping_fax_business */
      public String shippingFaxBusiness;
      /** @field VARCHAR(100) CIMSSchema.dbo.arinpchg.shipping_email */
      public String shippingEmail;
      /** @field VARCHAR(100) CIMSSchema.dbo.arinpchg.shipping_email2 */
      public String shippingEmail2;
      /** @field VARCHAR(100) CIMSSchema.dbo.arinpchg.shipping_website */
      public String shippingWebsite;
      /** @field TIMESTAMP(23) CIMSSchema.dbo.arinpchg.created_date */
      public Timestamp createdDate;
      /** @field VARCHAR(30) CIMSSchema.dbo.arinpchg.created_by */
      public String createdBy;
      /** @field TIMESTAMP(23) CIMSSchema.dbo.arinpchg.modified_date */
      public Timestamp modifiedDate;
      /** @field VARCHAR(30) CIMSSchema.dbo.arinpchg.modified_by */
      public String modifiedBy;
      /** @field VARCHAR(20) CIMSSchema.dbo.arinpchg.print_job_num *//*
      public String printJobNum;*/
      /**
      * The container assigned reference to the entity
      */
      private EntityContext context;

      /**
      * Sets the context of the bean
      * @param ec
      */
      public void setEntityContext(EntityContext ec) {
      context = ec;
      // to do: code goes here.
      }

      /**
      * Clears the context of the bean
      */
      public void unsetEntityContext() {
      this.context = null;
      // to do: code goes here.
      }

      /**
      * This method is called when the container picks this entity object
      * and assigns it to a specific entity object. Insert code here to
      * acquire any additional resources that it needs when it is in the
      * ready state.
      */
      public void ejbActivate() {
      }

      /**
      * This method is called when the container diassociates the bean
      * from the entity object identity and puts the instance back into
      * the pool of available instances. Insert code to release any
      * resources that should not be held while the instance is in the
      * pool.
      */
      public void ejbPassivate() {
      }

      /**
      * The container invokes this method on the bean whenever it
      * becomes necessary to synchronize the bean's state with the
      * state in the database. This method is called after the container
      * has loaded the bean's state from the database.
      */
      public void ejbLoad() {
      System.out.println("#### VJ: ChargeBean.ejbLoad()");
      }

      /**
      * The container invokes this method on the bean whenever it
      * becomes necessary to synchronize the state in the database
      * with the state of the bean. This method is called before the
      * container extracts the fields and writes them into the database.
      */
      public void ejbStore() {

      System.out.println("#### VJ: ChargeBean.ejbStore()");

      this.isDirty = false;
      updateTotals();

      System.out.println("#### VJ: ChargeBean.context.getPrimaryKey(): " + context.getPrimaryKey().toString());
      System.out.println("#### VJ: ChargeBean.trxNum: " + trxNum);

      }

      /**
      * The container invokes this method in response to a client-invoked
      * remove request. Insert code to implement any actions before the
      * bean is removed from the database.
      */
      public void ejbRemove() throws RemoveException {
      }


      public ChargePK ejbCreate(DCharge charge, DUser user)
      throws CreateException {

      System.out.println("#### VJ: ChargeBean.ejbCreate(DCharge, DUser)");

      Connection con = null;
      ChargePK key = new ChargePK();

      if (charge == null)
      throw new CreateException("charge cannot be null");
      if (user == null)
      throw new CreateException("user cannot be null");

      try {
      // set the pk
      con = DatabaseUtilities.getConnection(log, datasource);
      this.trxNum = AppJDBCHelper.getNextTrxNum(con);
      key.trxNum = this.trxNum;

      // set other attributes
      setAttributes(charge);

      // set mod history
      this.createdDate = new Timestamp(new java.util.Date().getTime());
      this.createdBy = user.getUsername();
      this.modifiedDate = new Timestamp(new java.util.Date().getTime());
      this.modifiedBy = user.getUsername();

      } catch (GetNextIdFailedException gnife) {
      log.error("ejbCreate", gnife);
      throw new CreateException(gnife.getMessage());
      } catch (NullPointerException ex1) {
      ex1.printStackTrace();
      log.warn("ejbCreate(): " + ex1);
      throw new CreateException("ejbCreate(): " + ex1);
      } finally {
      if (con != null) DatabaseUtilities.close(con, log, "ejbCreate()");
      }


      //System.out.println("#### VJ: ChargeBean.ejbCreate(DCharge, DUser) context.getPrimaryKey(): " + context.getPrimaryKey().toString());
      System.out.println("#### VJ: ChargeBean.ejbCreate(DCharge, DUser) (ChargeBean) trxNum: " + trxNum);
      System.out.println("#### VJ: ChargeBean.ejbCreate(DCharge, DUser) (ChargePK) key.trxNum: " + key.trxNum);
      System.out.println("#### VJ: ChargeBean.ejbCreate(DCharge, DUser) (DCharge): " + charge.getTrxNum());


      return (key);
      }

      /**
      * The container invokes this method after invoking the ejbCreate
      * method with the same arguments.
      * @param charge
      * @param user
      */
      public void ejbPostCreate(DCharge charge, DUser user) {

      System.out.println("#### VJ: ChargeBean.ejbPostCreate(DCharge, DUser)");

      updateTotals();
      isDirty = false;

      System.out.println("#### VJ: ChargeBean.ejbPostCreate(DCharge, DUser) context.getPrimaryKey(): " + context.getPrimaryKey().toString());
      System.out.println("#### VJ: ChargeBean.ejbPostCreate(DCharge, DUser) (ChargeBean) trxNum: " + trxNum);
      System.out.println("#### VJ: ChargeBean.ejbPostCreate(DCharge, DUser) (DCharge): " + charge.getTrxNum());

      }

      /**
      * @exception ReadFailedException
      * @return
      */
      public DCharge getDetails()
      throws ReadFailedException {

      DCharge charge = new DCharge();

      try {
      updateTotals();
      charge.setTrxNum(this.trxNum);

      getAttributes(charge);

      DModificationHistory history = new DModificationHistory();
      history.setCreatedDate(this.createdDate);
      history.setCreatedBy(this.createdBy);
      history.setModifiedDate(this.modifiedDate);
      history.setModifiedBy(this.modifiedBy);
      charge.setModificationHistory(history);
      } catch (InvalidDataException ex1) {
      log.warn("getDetails(): " + ex1);
      throw new ReadFailedException("getDetails(): " + ex1.toString());
      } catch (NullPointerException ex2) {
      log.warn("getDetails(): " + ex2);
      throw new ReadFailedException("getDetails(): " + ex2.toString());
      }

      return (charge);
      }

      /**
      * @exception ReadFailedException
      * @return
      */
      public DCharge getAllDetails()
      throws ReadFailedException {

      DCharge charge = null;

      try {
      // get non dependant object data
      charge = getDetails();


      // declare and init search home ejbs
      Context ctx = new InitialContext();

      // used for searching
      ChargePK chargePK = new ChargePK();
      chargePK.trxNum = this.trxNum;

      System.out.println("#### VJ: ChargeBean.getAllDetails() chargePK.trxNum(): " + chargePK.trxNum);
      System.out.println("#### VJ: ChargeBean.getAllDetails() charge.getTrxNum(): " + charge.getTrxNum());

      // load the charge line items
      try {
      Object obj = ctx.lookup("java:comp/env/ejb/au.com.cams.cims.ar.ejb.ChargeLineSearchHome");

      ChargeLineSearchHome chargeLineSearchHome = (ChargeLineSearchHome) PortableRemoteObject.narrow(obj, ChargeLineSearchHome.class);
      ChargeLineSearch chargeLineSearch = chargeLineSearchHome.create();
      System.out.println("ChargePK: " + chargePK.trxNum);
      charge.setLineItems(chargeLineSearch.searchByCharge(chargePK));

      } catch (NamingException ne) {
      log.warn("getAllDetails(): couldn't lookup ChargeLineSearchHome " + ne.toString());
      } catch (InvalidDataException ide) {
      log.warn("getAllDetails(): couldn't set ChargeLineSearchHome " + ide.toString());
      } catch (SearchFailedException sfe) {
      log.warn("getAllDetails(): search failed " + sfe.toString());
      } catch (CreateException ce) {
      log.warn("getAllDetails(): couldn't create ChargeLineSearchHome " + ce.toString());
      } catch (RemoteException re) {
      log.warn("getAllDetails(): " + re.toString());
      }
      } catch (NamingException ex) {
      log.warn("getAllDetails(): couldn't get an initial context " + ex.toString());
      throw new ReadFailedException("getAllDetails(): " + ex.toString());
      }

      return charge;
      }

      /**
      * @param charge
      * @param user
      * @exception UpdateFailedException
      */
      public void setDetails(DCharge charge, DUser user)
      throws UpdateFailedException {

      System.out.println("#### VJ: ChargeBean.setDetails(DCharge, DUser)");

      try {
      // set other attributes
      setAttributes(charge);
      updateTotals();

      // set mod history
      this.modifiedDate = new Timestamp(new java.util.Date().getTime());
      this.modifiedBy = user.getUsername();

      } catch (NullPointerException ex1) {
      log.warn("setDetails(): " + ex1);
      throw new UpdateFailedException("setDetails(): " + ex1.toString());
      }
      }

      /**
      * Increments the next sequenceId and returns the current sequenceId (before incrememt)
      * @exception java.rmi.RemoteException
      * @exception UpdateFailedException
      */
      public Integer incNextSequenceId()
      throws UpdateFailedException {

      Integer nextId = null;

      try {
      int current = this.nextSequenceId.intValue();

      // make a copy of the existing id
      nextId = new Integer(current);

      // now inc it
      this.nextSequenceId = new Integer(++current);
      } catch (EJBException e) {
      log.error("incNextSequenceId(): couldn't inc next sequenceId: " + e.toString());
      throw new UpdateFailedException(e.getMessage());
      }

      return nextId;
      }

      /**
      * Used by setDetails, ejbCreate.
      * @param member
      */
      protected void setAttributes(DCharge charge) {

      System.out.println("#### VJ: ChargeBean.setAttributes(DCharge)");


      this.isDirty = true;
      ARTransactionManager mgr = null;

      try {
      Context ctx = new InitialContext();

      Object obj = ctx.lookup("java:comp/env/ejb/au.com.cams.cims.ar.ejb.ARTransactionManagerHome");

      ARTransactionManagerHome mgrHome = (ARTransactionManagerHome) PortableRemoteObject.narrow(obj, ARTransactionManagerHome.class);
      mgr = mgrHome.create();

      } catch (NamingException ne) {
      log.warn("setAttributes(): couldn't lookup ARTransactionManagerHome " + ne.toString());
      throw new EJBException(ne.toString());
      } catch (CreateException ce) {
      log.warn("setAttributes(): couldn't create ARTransactionManagerHome " + ce.toString());
      throw new EJBException(ce.toString());
      } catch (RemoteException ex) {
      log.error(ex.toString());
      throw new EJBException(ex.toString());
      }

      try {
      TaxCode tc = mgr.getTaxCode(charge.getTaxCode());

      TaxAmounts amounts = ARUtilities.calculateTax(charge.getFreightAmount(), tc);
      this.taxOnFreightAmount = new Double(amounts.getAmountTax().doubleValue() - amounts.getAmountTaxIncluded().doubleValue());
      } catch (ReadFailedException rfe) {
      log.error("ReadFailedException reading tax code : " + charge.getTaxCode(), rfe);
      throw new EJBException(rfe.toString());
      } catch (RecordNotFoundException rnfe) {
      log.error("RecordNotFoundException reading tax code : " + charge.getTaxCode(), rnfe);
      throw new EJBException(rnfe.toString());
      } catch (RemoteException ex) {
      log.error(ex.toString());
      throw new EJBException(ex.toString());
      }

      System.out.println("#### VJ: ChargeBean.setAttributes(DCharge) prior setters");

      this.applyToNum = charge.getApplyToNum();
      this.termsCode = charge.getTermsCode();
      this.finChgCode = charge.getFinanceChargeCode();
      this.shippingCode = charge.getShippingCode();
      this.postingCode = charge.getPostingCode();
      this.taxCode = charge.getTaxCode();
      this.agingDate = new Timestamp(charge.getAgingDate().getTime());
      this.dueDate = new Timestamp(charge.getDueDate().getTime());
      this.grossAmount = charge.getGrossAmount();
      this.taxAmount = charge.getTaxAmount();
      this.taxIncludedAmount = charge.getTaxIncludedAmount();
      this.freightAmount = charge.getFreightAmount();


      this.netAmount = charge.getNetAmount();
      this.paidAmount = charge.getPaidAmount();
      this.dueAmount = charge.getDueAmount();
      this.trxType = charge.getTrxType();
      this.docNum = charge.getDocNum();
      this.docDate = new Timestamp(charge.getDocDate().getTime());
      this.applyDate = new Timestamp(charge.getApplyDate().getTime());
      this.debtorNum = charge.getDebtorNum();
      this.trxStatus = charge.getTrxStatus();
      this.approvalStatus = charge.getApprovalStatus();
      this.printingStatus = charge.getPrintingStatus();
      this.postingStatus = charge.getPostingStatus();
      this.holdStatus = charge.getHoldStatus();
      this.holdReason = charge.getHoldReason();
      this.notes = charge.getNotes();
      this.message = charge.getMessage();
      this.nextSequenceId = charge.getNextSequenceId();

      DAddress billingAddress = charge.getBillingAddress();
      if (billingAddress != null) {
      this.billingAddressee = billingAddress.getAddressee();
      this.billingJobPosition = billingAddress.getPosition();
      this.billingAddr1 = billingAddress.getAddress1();
      this.billingAddr2 = billingAddress.getAddress2();
      this.billingAddr3 = billingAddress.getAddress3();
      this.billingLocality = billingAddress.getLocality();
      this.billingState = billingAddress.getState();
      this.billingPostcode = billingAddress.getPostcode();
      this.billingCountry = billingAddress.getCountry();
      this.billingPhoneHome = billingAddress.getPhoneHome();
      this.billingPhoneBusiness = billingAddress.getPhoneBusiness();
      this.billingPhoneMobile = billingAddress.getPhoneMobile();
      this.billingPhoneCar = billingAddress.getPhoneCar();
      this.billingFaxHome = billingAddress.getFaxHome();
      this.billingFaxBusiness = billingAddress.getFaxBusiness();
      this.billingEmail = billingAddress.getEmail();
      this.billingEmail2 = billingAddress.getEmail2();
      this.billingWebsite = billingAddress.getWebsite();
      }

      DAddress shippingAddress = charge.getShippingAddress();
      if (shippingAddress != null) {
      this.shippingAddressee = shippingAddress.getAddressee();
      this.shippingJobPosition = shippingAddress.getPosition();
      this.shippingAddr1 = shippingAddress.getAddress1();
      this.shippingAddr2 = shippingAddress.getAddress2();
      this.shippingAddr3 = shippingAddress.getAddress3();
      this.shippingLocality = shippingAddress.getLocality();
      this.shippingState = shippingAddress.getState();
      this.shippingPostcode = shippingAddress.getPostcode();
      this.shippingCountry = shippingAddress.getCountry();
      this.shippingPhoneHome = shippingAddress.getPhoneHome();
      this.shippingPhoneBusiness = shippingAddress.getPhoneBusiness();
      this.shippingPhoneMobile = shippingAddress.getPhoneMobile();
      this.shippingPhoneCar = shippingAddress.getPhoneCar();
      this.shippingFaxHome = shippingAddress.getFaxHome();
      this.shippingFaxBusiness = shippingAddress.getFaxBusiness();
      this.shippingEmail = shippingAddress.getEmail();
      this.shippingEmail2 = shippingAddress.getEmail2();
      this.shippingWebsite = shippingAddress.getWebsite();
      }
      }

      /**
      * Used by getevent.
      * @param member
      * @exception au.com.cams.cims.core.util.InvalidDataException
      */
      protected void getAttributes(DCharge charge) throws InvalidDataException {
      charge.setApplyToNum(this.applyToNum);
      charge.setTermsCode(this.termsCode);
      charge.setFinanceChargeCode(this.finChgCode);
      charge.setShippingCode(this.shippingCode);
      charge.setPostingCode(this.postingCode);
      charge.setTaxCode(this.taxCode);
      charge.setAgingDate(this.agingDate);
      charge.setDueDate(this.dueDate);
      charge.setGrossAmount(this.grossAmount);
      charge.setTaxAmount(this.taxAmount);
      charge.setTaxIncludedAmount(this.taxIncludedAmount);
      charge.setFreightAmount(this.freightAmount);
      charge.setTaxOnFreightAmount(this.taxOnFreightAmount);
      charge.setNetAmount(this.netAmount);
      charge.setPaidAmount(this.paidAmount);
      charge.setDueAmount(this.dueAmount);
      charge.setTrxType(this.trxType);
      charge.setDocNum(this.docNum);
      charge.setDocDate(this.docDate);
      charge.setApplyDate(this.applyDate);
      charge.setDebtorNum(this.debtorNum);
      charge.setTrxStatus(this.trxStatus);
      charge.setApprovalStatus(this.approvalStatus);
      charge.setPrintingStatus(this.printingStatus);
      charge.setPostingStatus(this.postingStatus);
      charge.setHoldStatus(this.holdStatus);
      charge.setHoldReason(this.holdReason);
      charge.setNotes(this.notes);
      charge.setMessage(this.message);
      charge.setNextSequenceId(this.nextSequenceId);

      DAddress billingAddress = new DAddress();
      billingAddress.setAddressCode(DCharge.BILLING_ADDRESS);
      billingAddress.setAddressee(this.billingAddressee);
      billingAddress.setPosition(this.billingJobPosition);
      billingAddress.setAddress1(this.billingAddr1);
      billingAddress.setAddress2(this.billingAddr2);
      billingAddress.setAddress3(this.billingAddr3);
      billingAddress.setLocality(this.billingLocality);
      billingAddress.setState(this.billingState);
      billingAddress.setPostcode(this.billingPostcode);
      billingAddress.setCountry(this.billingCountry);
      billingAddress.setPhoneHome(this.billingPhoneHome);
      billingAddress.setPhoneBusiness(this.billingPhoneBusiness);
      billingAddress.setPhoneMobile(this.billingPhoneMobile);
      billingAddress.setPhoneCar(this.billingPhoneCar);
      billingAddress.setFaxHome(this.billingFaxHome);
      billingAddress.setFaxBusiness(this.billingFaxBusiness);
      billingAddress.setEmail(this.billingEmail);
      billingAddress.setEmail2(this.billingEmail2);
      billingAddress.setWebsite(this.billingWebsite);
      charge.setBillingAddress(billingAddress);

      DAddress shippingAddress = new DAddress();
      shippingAddress.setAddressCode(DCharge.SHIPPING_ADDRESS);
      shippingAddress.setAddressee(this.shippingAddressee);
      shippingAddress.setPosition(this.shippingJobPosition);
      shippingAddress.setAddress1(this.shippingAddr1);
      shippingAddress.setAddress2(this.shippingAddr2);
      shippingAddress.setAddress3(this.shippingAddr3);
      shippingAddress.setLocality(this.shippingLocality);
      shippingAddress.setState(this.shippingState);
      shippingAddress.setPostcode(this.shippingPostcode);
      shippingAddress.setCountry(this.shippingCountry);
      shippingAddress.setPhoneHome(this.shippingPhoneHome);
      shippingAddress.setPhoneBusiness(this.shippingPhoneBusiness);
      shippingAddress.setPhoneMobile(this.shippingPhoneMobile);
      shippingAddress.setPhoneCar(this.shippingPhoneCar);
      shippingAddress.setFaxHome(this.shippingFaxHome);
      shippingAddress.setFaxBusiness(this.shippingFaxBusiness);
      shippingAddress.setEmail(this.shippingEmail);
      shippingAddress.setEmail2(this.shippingEmail2);
      shippingAddress.setWebsite(this.shippingWebsite);
      charge.setShippingAddress(shippingAddress);
      }

      /**
      * Sets the address details for this Charge
      */
      public void setAddressDetails(DAddress addressDetails)
      throws UpdateFailedException {

      try {
      if (addressDetails == null)
      throw new IllegalArgumentException("addressDetails cannot be null");

      if (addressDetails.getAddressCode().equals(DCharge.BILLING_ADDRESS)) {
      this.billingAddressee = addressDetails.getAddressee();
      this.billingJobPosition = addressDetails.getPosition();
      this.billingAddr1 = addressDetails.getAddress1();
      this.billingAddr2 = addressDetails.getAddress2();
      this.billingAddr3 = addressDetails.getAddress3();
      this.billingLocality = addressDetails.getLocality();
      this.billingState = addressDetails.getState();
      this.billingPostcode = addressDetails.getPostcode();
      this.billingCountry = addressDetails.getCountry();
      this.billingPhoneHome = addressDetails.getPhoneHome();
      this.billingPhoneBusiness = addressDetails.getPhoneBusiness();
      this.billingPhoneMobile = addressDetails.getPhoneMobile();
      this.billingPhoneCar = addressDetails.getPhoneCar();
      this.billingFaxHome = addressDetails.getFaxHome();
      this.billingFaxBusiness = addressDetails.getFaxBusiness();
      this.billingEmail = addressDetails.getEmail();
      this.billingEmail2 = addressDetails.getEmail2();
      this.billingWebsite = addressDetails.getWebsite();

      } else if (addressDetails.getAddressCode().equals(DCharge.SHIPPING_ADDRESS)) {
      this.shippingAddressee = addressDetails.getAddressee();
      this.shippingJobPosition = addressDetails.getPosition();
      this.shippingAddr1 = addressDetails.getAddress1();
      this.shippingAddr2 = addressDetails.getAddress2();
      this.shippingAddr3 = addressDetails.getAddress3();
      this.shippingLocality = addressDetails.getLocality();
      this.shippingState = addressDetails.getState();
      this.shippingPostcode = addressDetails.getPostcode();
      this.shippingCountry = addressDetails.getCountry();
      this.shippingPhoneHome = addressDetails.getPhoneHome();
      this.shippingPhoneBusiness = addressDetails.getPhoneBusiness();
      this.shippingPhoneMobile = addressDetails.getPhoneMobile();
      this.shippingPhoneCar = addressDetails.getPhoneCar();
      this.shippingFaxHome = addressDetails.getFaxHome();
      this.shippingFaxBusiness = addressDetails.getFaxBusiness();
      this.shippingEmail = addressDetails.getEmail();
      this.shippingEmail2 = addressDetails.getEmail2();
      this.shippingWebsite = addressDetails.getWebsite();

      } else throw new IllegalArgumentException("addressDetails.addressCode is not recognised as a valid Charge address code");
      } catch (NullPointerException ex1) {
      log.warn("setAddressDetails(): " + ex1);
      throw new UpdateFailedException("setAddressDetails(): " + ex1.toString());
      }

      }

      /**
      * Get the requested address of code
      */
      public DAddress getAddressDetails(String code)
      throws ReadFailedException {

      try {
      if (code.equals(DCharge.BILLING_ADDRESS)) {
      DAddress billingAddress = new DAddress();
      billingAddress.setAddressCode(DCharge.BILLING_ADDRESS);
      billingAddress.setAddressee(this.billingAddressee);
      billingAddress.setPosition(this.billingJobPosition);
      billingAddress.setAddress1(this.billingAddr1);
      billingAddress.setAddress2(this.billingAddr2);
      billingAddress.setAddress3(this.billingAddr3);
      billingAddress.setLocality(this.billingLocality);
      billingAddress.setState(this.billingState);
      billingAddress.setPostcode(this.billingPostcode);
      billingAddress.setCountry(this.billingCountry);
      billingAddress.setPhoneHome(this.billingPhoneHome);
      billingAddress.setPhoneBusiness(this.billingPhoneBusiness);
      billingAddress.setPhoneMobile(this.billingPhoneMobile);
      billingAddress.setPhoneCar(this.billingPhoneCar);
      billingAddress.setFaxHome(this.billingFaxHome);
      billingAddress.setFaxBusiness(this.billingFaxBusiness);
      billingAddress.setEmail(this.billingEmail);
      billingAddress.setEmail2(this.billingEmail2);
      billingAddress.setWebsite(this.billingWebsite);

      return(billingAddress);

      } else if (code.equals(DCharge.SHIPPING_ADDRESS)) {
      DAddress shippingAddress = new DAddress();
      shippingAddress.setAddressCode(DCharge.SHIPPING_ADDRESS);
      shippingAddress.setAddressee(this.shippingAddressee);
      shippingAddress.setPosition(this.shippingJobPosition);
      shippingAddress.setAddress1(this.shippingAddr1);
      shippingAddress.setAddress2(this.shippingAddr2);
      shippingAddress.setAddress3(this.shippingAddr3);
      shippingAddress.setLocality(this.shippingLocality);
      shippingAddress.setState(this.shippingState);
      shippingAddress.setPostcode(this.shippingPostcode);
      shippingAddress.setCountry(this.shippingCountry);
      shippingAddress.setPhoneHome(this.shippingPhoneHome);
      shippingAddress.setPhoneBusiness(this.shippingPhoneBusiness);
      shippingAddress.setPhoneMobile(this.shippingPhoneMobile);
      shippingAddress.setPhoneCar(this.shippingPhoneCar);
      shippingAddress.setFaxHome(this.shippingFaxHome);
      shippingAddress.setFaxBusiness(this.shippingFaxBusiness);
      shippingAddress.setEmail(this.shippingEmail);
      shippingAddress.setEmail2(this.shippingEmail2);
      shippingAddress.setWebsite(this.shippingWebsite);

      return(shippingAddress);

      } else throw new IllegalArgumentException("code is not recognised as a valid Charge address code");
      } catch (InvalidDataException ex) {
      log.warn("getAddressDetails(): invalid data exception: " + ex.toString());
      throw new ReadFailedException("getAddressDetails(): invalid data exception: " + ex.toString());
      }
      }

      public ChargeLine addChargeLine(DChargeLine chargeLine, DUser user)
      throws CIMSApplicationException {

      ChargeLineHome clhome = null;

      try {
      clhome = getChargeLineHome();

      log.debug("About to get pk");

      ChargePK pk = (ChargePK)context.getPrimaryKey();

      log.debug("About to create for trx " + pk.trxNum);

      ChargeLine cl = clhome.create(chargeLine, user, pk, incNextSequenceId());

      log.debug("addChargeLine()");
      System.out.println("BEAN Line tax included = " + cl.getAllDetails().getTaxIncludedAmount());

      updateTotals();

      return cl;


      } catch (CreateException ce) {
      log.error("Could not create the chargeLine entity" + ce.toString());
      throw new InsertFailedException("Create ChargeLine failed " + ce.toString());
      } catch (RemoteException re) {
      log.error("Remote Exception creating the chargeLine entity" + re.toString(), re);
      throw new InsertFailedException("Create ChargeLine failed " + re.toString());
      }


      }

      public ChargeLine addChargeLine(DChargeLine chargeLine, DUser user, Integer sequenceId)
      throws CIMSApplicationException {

      ChargeLineHome clhome = null;

      try {
      clhome = getChargeLineHome();

      log.debug("About to get pk");

      ChargePK pk = (ChargePK)context.getPrimaryKey();

      log.debug("About to create for trx " + pk.trxNum);

      ChargeLine cl = clhome.create(chargeLine, user, pk, sequenceId);

      log.debug("addChargeLine()");

      updateTotals();

      return cl;


      } catch (CreateException ce) {
      log.error("Could not create the chargeLine entity" + ce.toString());
      throw new InsertFailedException("Create ChargeLine failed " + ce.toString());
      } catch (RemoteException re) {
      log.error("Remote Exception creating the chargeLine entity" + re.toString(), re);
      throw new InsertFailedException("Create ChargeLine failed " + re.toString());
      }


      }

      public void modifyChargeLine(DChargeLine chargeLine, DUser user)
      throws CIMSApplicationException {

      ChargeLineHome clhome = null;
      ChargeLine line = null;

      try {
      clhome = getChargeLineHome();

      ChargeLinePK pk = new ChargeLinePK();

      pk.trxNum = chargeLine.getTrxNum();
      pk.sequenceId = chargeLine.getSequenceId();

      line = clhome.findByPrimaryKey(pk);

      line.setDetails(chargeLine, user);

      line.getDetails();

      log.debug("ModifyChargeLine()");

      updateTotals();


      } catch (FinderException ce) {
      log.error("Could not find the chargeLine entity" + ce.toString());
      throw new ReadFailedException("Modify ChargeLine failed " + ce.toString());
      } catch (RemoteException re) {
      log.error("Remote Exception updating the chargeLine entity" + re.toString(), re);
      throw new UpdateFailedException("Modify ChargeLine failed " + re.toString());
      }

      }

      public void deleteChargeLine(ChargeLinePK pk)
      throws CIMSApplicationException {

      ChargeLineHome clhome = null;
      ChargeLine line = null;

      try {
      clhome = getChargeLineHome();

      line = clhome.findByPrimaryKey(pk);

      line.remove();
      log.debug("DeleteChargeLine()");

      updateTotals();

      } catch (FinderException fe) {
      log.error("ChargeLine doesn't exist " + fe);
      throw new DeleteFailedException("ChargeLine doesn't exist " + fe);
      } catch (RemoveException ce) {
      log.error("Could not delete the chargeLine entity" + ce.toString());
      throw new DeleteFailedException("delete ChargeLine failed " + ce.toString());
      } catch (RemoteException re) {
      log.error("Remote Exception deleting the chargeLine entity" + re.toString(), re);
      throw new EJBException("delete ChargeLine failed " + re.toString());
      }

      }

      private ChargeLineHome getChargeLineHome() {

      ChargeLineHome home = null;
      try {
      Context ctx = new InitialContext();

      home = (ChargeLineHome) PortableRemoteObject.narrow(ctx.lookup(chargeLineRef), ChargeLineHome.class);

      return home;


      } catch (NamingException ne) {
      log.error("Naming Exception in getChargeLineHome()" + ne.toString(), ne);
      throw new EJBException(ne.toString());
      }

      }

      public void updateTotals() {

      ARTransactionManager mgr = null;

      try {
      log.debug("updateTotals()");

      try {
      Context ctx = new InitialContext();

      Object obj = ctx.lookup("java:comp/env/ejb/au.com.cams.cims.ar.ejb.ARTransactionManagerHome");

      ARTransactionManagerHome mgrHome = (ARTransactionManagerHome) PortableRemoteObject.narrow(obj, ARTransactionManagerHome.class);
      mgr = mgrHome.create();

      } catch (NamingException ne) {
      log.warn("updateTotals(): couldn't lookup ARTransactionManagerHome " + ne.toString());
      throw new EJBException(ne.toString());
      } catch (CreateException ce) {
      log.warn("updateTotals(): couldn't create ARTransactionManagerHome " + ce.toString());
      throw new EJBException(ce.toString());
      }

      ChargeTotals totals = mgr.getChargeTotals((ChargePK)context.getPrimaryKey());

      this.grossAmount = totals.getExtendedTotal();
      this.taxAmount = totals.getTaxAmountTotal();
      this.taxIncludedAmount = totals.getTaxIncludedTotal();
      System.out.println("BEAN Charge tax included = " + this.taxIncludedAmount);
      this.netAmount = new Double(this.grossAmount.doubleValue() + this.taxAmount.doubleValue() - this.taxIncludedAmount.doubleValue() + this.freightAmount.doubleValue() + this.taxOnFreightAmount.doubleValue());
      this.dueAmount = new Double(this.netAmount.doubleValue() - this.paidAmount.doubleValue());

      log.debug("updateTotals(): netAmount: " + this.netAmount);

      } catch (ReadFailedException rfe) {
      log.debug("Under ReadFailedException");
      log.error("Error Updating totals of charge " + rfe);
      throw new EJBException(rfe.toString());
      } catch (RemoteException re) {
      log.debug("Under RemoteException");
      log.warn("updateTotals(): " + re.toString());
      throw new EJBException(re.toString());
      }
      isDirty = true;
      log.debug("out of update totals finally");
      }

      /**
      * Method use to automatically populate charge lines for credit note charges
      * based on the reference invoice.
      */
      public void populateLines(DUser user)
      throws UpdateFailedException {

      if (!(this.trxType.intValue() == DARTransaction.TRX_TYPE_CREDIT_NOTE))
      return;

      // check that applyToNum is not null and reference an invoice
      // if it is null or does not reference an invoice, return.
      if (this.applyToNum == null || this.applyToNum.length() < 1)
      return;

      try {
      List results = searchByApplyToDocNum(this.applyToNum);

      if (results != null || results.size() > 0) {

      int seq = 1;

      ARTransactionSearchResultsItem item = (ARTransactionSearchResultsItem)results.get(0);

      List lines = getChargeLines(item.getARTransaction().getTrxNum());
      // Iterate over the lines, setting the trxNum, trxType to this credit note
      // and call addChargeLine
      if (lines != null) {
      for (Iterator i = lines.iterator(); i.hasNext(); ) {
      DChargeLine line = (DChargeLine)i.next();

      line.setTrxNum(this.trxNum);
      line.setTrxType(this.trxType);
      line.setSrcTrxId(new Integer(0));
      line.setSrcTrxType(new Integer(0));

      addChargeLine(line, user, new Integer(seq++));
      }
      }

      this.nextSequenceId = new Integer(seq);
      }

      } catch (SearchFailedException ex) {
      log.debug(ex.toString());
      // do nothing, there is no invoice referenced so do nothing
      } catch (RecordNotFoundException ex) {
      log.debug(ex.toString());
      // do nothing, the referenced has no lines so do nothing
      } catch (InvalidDataException ex) {
      // this should never happen unless data in db is corrupt
      log.error(ex.toString());
      throw new UpdateFailedException(ex.toString());
      } catch (RemoteException ex) {
      log.error(ex.toString());
      throw new UpdateFailedException(ex.toString());
      }
      }

      private List searchByApplyToDocNum(String docNum)
      throws RemoteException, SearchFailedException {

      try {
      Context ctx = new InitialContext();

      Object obj = ctx.lookup("java:comp/env/ejb/au.com.cams.cims.ar.ejb.ARTransactionSearchHome");

      ARTransactionSearchHome home = (ARTransactionSearchHome) PortableRemoteObject.narrow(obj, ARTransactionSearchHome.class);
      ARTransactionSearch entity = home.create();

      // form criteria
      ARTransactionSearchCriteria criteria = new ARTransactionSearchCriteria();
      criteria.setTrxType(new Integer(DARTransaction.TRX_TYPE_INVOICE));
      criteria.setDocNumFrom(docNum);
      criteria.setDocNumThrough(docNum);

      SearchResults results = entity.searchSpecificFields(criteria, 1, 1);

      return results.getResults();

      } catch (NamingException ne) {
      log.warn("searchByApplyToDocNum(): couldn't lookup ARTransactionSearchHome " + ne.toString());
      throw new EJBException(ne.toString());
      } catch (CreateException ce) {
      log.warn("searchByApplyToDocNum(): couldn't create ARTransactionSearchHome " + ce.toString());
      throw new EJBException(ce.toString());
      }
      }

      private List getChargeLines(String refTrxNum)
      throws RemoteException, RecordNotFoundException {

      try {
      Context ctx = new InitialContext();

      Object obj = ctx.lookup("java:comp/env/ejb/au.com.cams.cims.ar.ejb.ARTransactionManagerHome");

      ARTransactionManagerHome home = (ARTransactionManagerHome) PortableRemoteObject.narrow(obj, ARTransactionManagerHome.class);
      ARTransactionManager entity = home.create();

      DARTransaction trans = entity.getAllTransactionDetails(refTrxNum);

      return ((DCharge)trans).getLineItems();

      } catch (NamingException ne) {
      log.warn("getChargeLines(): couldn't lookup ARTransactionManagerHome " + ne.toString());
      throw new EJBException(ne.toString());
      } catch (CreateException ce) {
      log.warn("getChargeLines(): couldn't create ARTransactionManagerHome " + ce.toString());
      throw new EJBException(ce.toString());
      }
      }



      }


      THE METHOD FROM WHERE THE ERROR OCCURS IS:

      public PendingChargeResponse processPendingCharges(
      PendingChargeRequest request, DUser user)
      throws StoredProcedureFailedException, UpdateFailedException {
      System.out.println("***** process pending charges ****");
      log.debug("Inside processPendingCharges");
      Connection con = null;
      Context ctx = null;

      // create Charge
      DDebtor debtorDetail = null;

      DCharge chargeDetail = null;
      Charge chargeEntity = null;
      List pendingCharges = null;
      List pendingPayments = null;
      List paymentTrxNumList = null;

      String invoiceTrxNum = null;
      String creditNoteTrxNum = null;