Hi Thomas,

I solved this mapping problems. Now I can do update of object to the
database. Whereas, if I want to add in a new line item PrItemBO class to
the PrBO class. The new line item is not persist to the database. Where
did I get wrong???? 

When is the right place to lock the object?  

Thanks in advance

Cheers,
Stephen

public boolean updatePR(PrView view, Site site) throws
BusinessDelegateException {
        Implementation odmg = OJB.getInstance();
        Database db = odmg.newDatabase();
        Transaction tx = null;
        
        try
        {   
            db.open(site.getRepository(), Database.OPEN_READ_WRITE);
            tx = odmg.newTransaction();            
            tx.begin();
            PersistenceBroker broker = ((HasBroker) tx).getBroker();
            PrBO prUpdate = new PrBO();
            
            prUpdate.setPrNo(view.getPrNo());
            prUpdate.setMailId(view.getMailId());
            prUpdate.setIssuedBy(view.getIssuedBy());
            prUpdate.setCompanyNo(view.getCompanyNo());
            String viewDate = view.getPrDate();
            SimpleDateFormat newFormat = new
SimpleDateFormat("dd/MM/yyyy");//sql db compliant
            Date newDate = null;
            try{                
                newDate = newFormat.parse(viewDate);
            }catch(ParseException e){
                System.out.println(e.getMessage());
            }
            
            prUpdate.setPrDate(new Timestamp(newDate.getTime()));

            tx.lock(prUpdate,tx.WRITE);      
            
            Iterator iterate = view.getItemList().values().iterator();

            while(iterate.hasNext()){
                PrItemBO itemBO = new PrItemBO();
                PrItemBO duplicateItem = null;                
                try{
                    PrItemView itemView = (PrItemView) iterate.next();
                          //Try to add in the Line item         
                    if("A".equals(itemView.getProcessed())){
                        duplicateItem = new PrItemBO();
                        PropertyUtils.copyProperties(duplicateItem,
itemView);
                        duplicateItem.setVendorNo("");
                        duplicateItem.setQtyAprv(new BigDecimal(0.0));
                        duplicateItem.setProcessed("P");
                        prUpdate.addItem(duplicateItem);
                        duplicateItem.setPrBO(prUpdate);
                    }
                    PropertyUtils.copyProperties(itemBO, itemView);
                    prUpdate.addItem(itemBO);
                    itemBO.setPrBO(prUpdate);
                }catch(Exception e){
                    System.out.println(e.getMessage());
                }                                
            }
            tx.lock(prUpdate,tx.WRITE); 

            tx.commit();
            broker.clearCache();
            db.close();
            
        }catch(ODMGException e){
            tx.abort();
            System.out.println(e.getMessage());
            return false;
        }
            
        return true;
    }    



> -----Original Message-----
> From: Thomas Mahler [mailto:[EMAIL PROTECTED]]
> Sent: 29 November 2002 17:43
> To: OJB Users List
> Subject: Re: One-to-many update error
> 
> 
> Hi STephen,
> 
> This is a mapping error as indicated by the ERROR messages.
> AFAIK PrItemBO does have a property prNo. The (derived ?) 
> class PrItemView does not have the respective 
> getter/setter method?
> 
> Try to add these getter/setter on PrItemView.
> You could also try to use a different PersistentField
> Implementation in 
>   OJB.properties.
> 
> cheers,
> Thomas
> 
> Stephen Ting wrote:
> > What cause the following errors being thrown?
> > The following code is used, where prUpdate is of class PrBO
> and have
> > one to many relationship with PrItemBO class.
> >  
> >  
> >             db.open(site.getRepository(), Database.OPEN_READ_WRITE);
> >             tx = odmg.newTransaction();
> >             tx.begin();
> >             tx.lock(prUpdate,tx.WRITE);
> >             tx.commit();
> >  
> > Can someone please help???
> >  
> > Thanks in advance!
> >  
> > regards,
> > Stephen
> >  
> > [DEFAULT] ERROR: Error in operation [set] of object
> > [PersistentFieldPropertyImpl], java.lang.IllegalArgumentException
> > [DEFAULT] ERROR: Declaring class 
> > [my.com.shinyang.einout.business.bo.PrItemBO]
> > [DEFAULT] ERROR: Property Name [prNo]
> > [DEFAULT] ERROR: Property Type [java.lang.String]
> > [DEFAULT] ERROR: anObject was class 
> > [my.com.shinyang.einout.purchase.requisition.view.PrItemView]
> > [DEFAULT] ERROR: aValue was class [java.lang.String] 
> > [org.apache.ojb.odmg.TransactionImpl] ERROR: Locking obj 
> > my.com.shinyang.einout.business.bo.PrBO@694f12 with lock 
> mode 4 failed
> > null org.apache.ojb.broker.PersistenceBrokerException
> >  at
> > 
> org.apache.ojb.broker.metadata.PersistentFieldPropertyImpl.set(Unknown
> > Source)
> >  at
> org.apache.ojb.odmg.TransactionImpl.lockCollections(Unknown Source)
> >  at org.apache.ojb.odmg.TransactionImpl.register(Unknown Source)  at

> > org.apache.ojb.odmg.TransactionImpl.lock(Unknown Source)  at
> > 
> my.com.shinyang.einout.business.PurchaseRequisitionDelegateImp
> l.updatePR
> > (PurchaseRequisitionDelegateImpl.java:334)
> >  at
> > 
> my.com.shinyang.einout.purchase.requisition.PurchaseApprovalEd
> itAction.u
> > pdate(PurchaseApprovalEditAction.java:129)
> >  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  at
> > 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccess
> orImpl.jav
> > a:39)
> >  at
> > 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMeth
> odAccessor
> > Impl.java:25)
> >  at java.lang.reflect.Method.invoke(Method.java:324)
> >  at
> > 
> org.apache.struts.actions.DispatchAction.dispatchMethod(Dispat
> chAction.j
> > ava:280)
> >  at
> > 
> org.apache.struts.actions.DispatchAction.execute(DispatchActio
> n.java:220
> > )
> >  at
> > 
> org.apache.struts.action.RequestProcessor.processActionPerform
> (RequestPr
> > ocessor.java:446)
> >  at
> > 
> org.apache.struts.action.RequestProcessor.process(RequestProce
> ssor.java:
> > 266)
> >  at
> > 
> org.apache.struts.action.ActionServlet.process(ActionServlet.j
> ava:1292)
> >  at
> > 
> org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:510)
> >  at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
> >  at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
> >  at
> > 
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilt
> er(Applica
> > tionFilterChain.java:247)
> >  at
> > 
> org.apache.catalina.core.ApplicationFilterChain.doFilter(Appli
> cationFilt
> > erChain.java:193)
> >  at
> > 
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardW
> rapperValv
> > e.java:260)
> >  at
> > 
> org.apache.catalina.core.StandardPipeline$StandardPipelineValv
> eContext.i
> > nvokeNext(StandardPipeline.java:643)
> >  at
> > 
> org.apache.catalina.core.StandardPipeline.invoke(StandardPipel
> ine.java:4
> > 80)
> >  at
> > 
> org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
> >  at
> > 
> org.apache.catalina.core.StandardContextValve.invoke(StandardC
> ontextValv
> > e.java:191)
> >  at
> > 
> org.apache.catalina.core.StandardPipeline$StandardPipelineValv
> eContext.i
> > nvokeNext(StandardPipeline.java:643)
> >  at
> > 
> org.apache.catalina.authenticator.AuthenticatorBase.invoke(Aut
> henticator
> > Base.java:527)
> >  at
> > 
> org.apache.catalina.core.StandardPipeline$StandardPipelineValv
> eContext.i
> > nvokeNext(StandardPipeline.java:641)
> >  at
> > 
> org.apache.catalina.core.StandardPipeline.invoke(StandardPipel
> ine.java:4
> > 80)
> >  at
> > 
> org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
> >  at
> > 
> org.apache.catalina.core.StandardContext.invoke(StandardContex
> t.java:235
> > 0)
> >  at
> > 
> org.apache.catalina.core.StandardHostValve.invoke(StandardHost
> Valve.java
> > :180)
> >  at
> > 
> org.apache.catalina.core.StandardPipeline$StandardPipelineValv
> eContext.i
> > nvokeNext(StandardPipeline.java:643)
> >  at
> > 
> org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDi
> spatcherVa
> > lve.java:170)
> >  at
> > 
> org.apache.catalina.core.StandardPipeline$StandardPipelineValv
> eContext.i
> > nvokeNext(StandardPipeline.java:641)
> >  at
> > 
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReport
> Valve.java
> > :171)
> >  at
> > 
> org.apache.catalina.core.StandardPipeline$StandardPipelineValv
> eContext.i
> > nvokeNext(StandardPipeline.java:641)
> >  at
> > 
> org.apache.catalina.core.StandardPipeline.invoke(StandardPipel
> ine.java:4
> > 80)
> >  at
> > 
> org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
> >  at
> > 
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEn
> gineValve.
> > java:174)
> >  at
> > 
> org.apache.catalina.core.StandardPipeline$StandardPipelineValv
> eContext.i
> > nvokeNext(StandardPipeline.java:643)
> >  at
> > 
> org.apache.catalina.core.StandardPipeline.invoke(StandardPipel
> ine.java:4
> > 80)
> >  at
> > 
> org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
> >  at
> > 
> org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.
> java:223)
> >  at
> > 
> org.apache.coyote.http11.Http11Processor.process(Http11Process
> or.java:40
> > 5)
> >  at
> > 
> org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandle
> r.processC
> > onnection(Http11Protocol.java:380)
> >  at
> > 
> org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoi
> nt.java:50
> > 8)
> >  at
> > 
> org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(
> ThreadPool
> > .java:533)
> >  at java.lang.Thread.run(Thread.java:536)
> > Caused by: java.lang.IllegalArgumentException: object is
> not an instance
> > of declaring class
> >  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  at
> > 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccess
> orImpl.jav
> > a:39)
> >  at
> > 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMeth
> odAccessor
> > Impl.java:25)
> >  at java.lang.reflect.Method.invoke(Method.java:324)
> >  ... 49 more
> > 
> 
> 
> 
> --
> To unsubscribe, e-mail:   
> <mailto:ojb-user-> [EMAIL PROTECTED]>
> For
> additional commands, 
> e-mail: <mailto:[EMAIL PROTECTED]>
> 
> 


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to