Hi Andre,

I guess the problem is: the collection returned by getCollectionByQuery() 
contains dynamic proxies, not MGT_Requests. So you should cast to an 
interface that MGT_Request should implement if you want to use dynamic 
proxies (does it?), see 
http://db.apache.org/ojb/tutorial3.html#Using%20Dynamic%20Proxies
You may force materialization, just call "get" method for some persistent 
field before 
   results.add(resMGT_Request);
BTW your current workaround should be quite efficient due to proxy prefetching 
(new OJB feature).

Regards,
 Oleg

On Tuesday 27 January 2004 13:04, A Leg wrote:
> Oleg
>
> Thank you for your answer.
> emptyArray is just empty.
> And it is correct if you refer to Collection.toArray apiDoc.
> I made tries with and without emtyArray param, taking in count that both
> solutions exists.
> And I get the same result.
> Plus it works good when I fill the Collection by this code : (I use
> getCollectionByQuery only to get the iterator).
>
>
>         Iterator iter = collectionResult.iterator();
>         Collection results = new Vector();
>         while (iter.hasNext())
>         {
>             exMGT_Request.setJobNum(new BigDecimal(id));
>                 resMGT_Request = broker.getObjectByQuery(new
> QueryByIdentity(exMGT_Request));
>         iter.next();
>         results.add(resMGT_Request);
>         id++;
>         }
>       MGT_Request[] resArray = (MGT_Request[])results.toArray(emptyArray);
>
> I use this code as turnaround. But as you can see it is not realy very
> efficient.
> If I try to use data of iter.next() casting them to MGT_Request, it just
> fail also. For this reason my conclusion is that the elements of the
> Collection returned by getCollectionByQuery are only not valids.
> I use postgres as dataBase and everything is working good with it beside
> that.
>
> I would appreciate any help, because the turnaround is so bad that I
> would prefer to drop it.
>
> Best regards
>
> Andre Legendre
>
> Oleg Nitz wrote:
> >Hi Andre,
> >
> >This is more like incorrect usage of Collection.toArray() method
> >than OJB related problem.
> >Please print emptyArray and emptyArray.length before the line
> >
> >>     MGT_Request[] resArray = (MGT_Request[])acc.toArray(emptyArray);
> >
> >Is emptyArray not null?
> >Is emptyArray.length really 0?
> >
> >Regards,
> > Oleg
> >
> >On Sunday 25 January 2004 13:22, A Leg wrote:
> >>Hi
> >>
> >>I get some more elements on my getCollectionByQuery problem.
> >>
> >>It seems that elements of the Collection I get are not valid to be
> >>casted by my class.
> >>If I change to put an Iterator on the Collection it works good as soon I
> >>don't try to cast to my Objects.
> >>
> >>Does anybody can help me ?
> >>I am realy stuck.
> >>
> >>Andre
> >>
> >>I change the code to :
> >>
> >>System.out.println("Send COLLECTIONQUERY MGT ");
> >>            Collection results =
> >>(Collection)broker.getCollectionByQuery(listQuery);
> >>            //System.out.println("Get COLLECTIONQUERY MGT Rows : " +
> >>results.size());
> >>            System.out.println("Get COLLECTIONQUERY MGT Rows : INCONNU");
> >>        Iterator iter = results.iterator();
> >>        Collection acc = new Vector();
> >>            System.out.println("Get COLLECTIONQUERY ojbIterator get ");
> >>        MGT_Request tmpReq = new MGT_Request();
> >>            System.out.println("Get COLLECTIONQUERY ojbIterator iter");
> >>        while (iter.hasNext())
> >>        {
> >>        acc.add(iter.next());
> >>        }
> >>            System.out.println("Get COLLECTIONQUERY ojbIterator done ");
> >>        MGT_Request[] resArray = (MGT_Request[])acc.toArray(emptyArray);
> >>            System.out.println("Get COLLECTIONQUERY toArray done ");
> >>
> >>And I got the error message :
> >>
> >>Send COLLECTIONQUERY MGT
> >>Get COLLECTIONQUERY MGT Rows : INCONNU
> >>Get COLLECTIONQUERY ojbIterator get
> >>Get COLLECTIONQUERY ojbIterator iter
> >>Get COLLECTIONQUERY ojbIterator done
> >>java.lang.ArrayStoreException
> >>        at java.lang.System.arraycopy(Native Method)
> >>        at java.util.Vector.toArray(Vector.java:688)
> >>        at
> >>org.compiere.mfg_scm.dbManager.TaskConsumer.mfgGetCollectionByQuery(Unkno
> >>wn Source)
> >>        at
> >>org.compiere.mfg_scm.dbManager.DbManagerImpl.mfgGetCollectionByQuery(Unkn
> >>ow n Source)
> >>        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> >>        at
> >>sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java
> >>:3 9) at
> >>sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorI
> >>mp l.java:25) at java.lang.reflect.Method.invoke(Method.java:324)
> >>        at
> >>sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
> >>        at sun.rmi.transport.Transport$1.run(Transport.java:148)
> >>        at java.security.AccessController.doPrivileged(Native Method)
> >>        at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
> >>        at
> >>sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
> >>        at
> >>sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.jav
> >>a: 701) at java.lang.Thread.run(Thread.java:534)
> >>
> >>A Leg wrote:
> >>>Hi
> >>>
> >>>I have some problem using getCollectionByQuery.
> >>>
> >>>Here is the peace of Code :
> >>>
> >>>           System.out.println("Send COLLECTIONQUERY MGT ");
> >>>           Collection results =
> >>>(Collection)broker.getCollectionByQuery(listQuery);
> >>>           System.out.println("Get COLLECTIONQUERY MGT Rows : " +
> >>>results.size());
> >>>       MGT_Request[] resArray =
> >>>(MGT_Request[])results.toArray(emptyArray);
> >>>           System.out.println("Get COLLECTIONQUERY toArray done ");
> >>>
> >>>I get this trace :
> >>>
> >>>Send COLLECTIONQUERY MGT
> >>>Get COLLECTIONQUERY MGT Rows : 2
> >>>java.lang.ArrayStoreException
> >>>       at java.lang.System.arraycopy(Native Method)
> >>>       at java.util.Vector.toArray(Vector.java:688)
> >>>       at
> >>>org.compiere.mfg_scm.dbManager.TaskConsumer.mfgGetCollectionByQuery(Unkn
> >>>o wn Source)
> >>>       at
> >>>org.compiere.mfg_scm.dbManager.DbManagerImpl.mfgGetCollectionByQuery(Unk
> >>>n own Source)
> >>>       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> >>>       at
> >>>sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jav
> >>>a
> >>>
> >>>:39)
> >>>
> >>>       at
> >>>sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessor
> >>>I mpl.java:25)
> >>>
> >>>       at java.lang.reflect.Method.invoke(Method.java:324)
> >>>       at
> >>>sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
> >>>       at sun.rmi.transport.Transport$1.run(Transport.java:148)
> >>>       at java.security.AccessController.doPrivileged(Native Method)
> >>>       at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
> >>>       at
> >>>sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
> >>>       at
> >>>sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.ja
> >>>v a:701)
> >>>
> >>>       at java.lang.Thread.run(Thread.java:534)
> >>>
> >>>I have 2 records in my test table, so the size is good.
> >>>But methods of Collection to extract objects from the Collection :
> >>>Iterator, toArray seems to have problem with the results Collection.
> >>>
> >>>When using the pb broker with getObjectByQuery on the same table and
> >>>same object it is working good.
> >>>
> >>>I am using db-ojb-1.0.rc4
> >>>
> >>>Can anybody help me, I turn alone this problem from one day and get no
> >>>progress.
> >>>
> >>>Andre Legendre
> >>>
> >>>
> >>>---------------------------------------------------------------------
> >>>To unsubscribe, e-mail: [EMAIL PROTECTED]
> >>>For additional commands, e-mail: [EMAIL PROTECTED]
> >>
> >>---------------------------------------------------------------------
> >>To unsubscribe, e-mail: [EMAIL PROTECTED]
> >>For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: [EMAIL PROTECTED]
> >For additional commands, e-mail: [EMAIL PROTECTED]
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]


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

Reply via email to