You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by "M. Walter" <ma...@sbb.ch> on 2011/09/08 15:33:59 UTC

Using FetchPlan.setFetchBatchSize() feature leads to java.io.NotSerializableException

In my code I would like to set the fetch batch size in order to "speed up"
loading entities:

final OpenJPAQuery ojpaQuery =
OpenJPAPersistence.cast(em.createNamedQuery(myNiceQuery));
ojpaQuery.getFetchPlan().setFetchBatchSize(2000);
final List result = ojpaQuery.getResultList();

The result list should be sent to a RCP client.
Now I wonder why I get java.io.NotSerializableException on the client side
using this feature:

Exception in thread "P=573122:O=0:CT" java.rmi.MarshalException: CORBA
BAD_PARAM 0x4f4d0006 Maybe; nested exception is: 
	java.io.NotSerializableException: 
	>> SERVER (id=4773e3aa, host=myhost.mycompany.com) TRACE START:
	>>    org.omg.CORBA.BAD_PARAM:
org.apache.openjpa.datacache.QueryCacheStoreQuery$CachingResultObjectProvider
is not serializable  vmcid: OMG  minor code: 6 completed: Maybe
	>>	 at
com.ibm.rmi.util.Utility.throwNotSerializableForCorba(Utility.java:1661)
	>>	 at
com.ibm.rmi.io.IIOPOutputStream.writeValueType(IIOPOutputStream.java:1142)
	>>	 at
com.ibm.rmi.io.IIOPOutputStream.writeObjectField(IIOPOutputStream.java:1082)
	>>	 at
com.ibm.rmi.io.IIOPOutputStream.outputClassFields(IIOPOutputStream.java:1013)
	>>	 at
com.ibm.rmi.io.IIOPOutputStream.outputObject(IIOPOutputStream.java:997)
	>>	 at
com.ibm.rmi.io.IIOPOutputStream.continueSimpleWriteObject(IIOPOutputStream.java:484)
	>>	 at
com.ibm.rmi.io.IIOPOutputStream.simpleWriteObjectLoop(IIOPOutputStream.java:464)
	>>	 at
com.ibm.rmi.io.IIOPOutputStream.simpleWriteObject(IIOPOutputStream.java:528)
	>>	 at
com.ibm.rmi.io.ValueHandlerImpl.writeValue(ValueHandlerImpl.java:168)
	>>	 at com.ibm.rmi.iiop.CDRWriter.write_value(CDRWriter.java:1195)
	>>	 at com.ibm.rmi.iiop.CDRWriter.write_value(CDRWriter.java:1213)
	>>	 at
com.ibm.rmi.iiop.CDRWriter.write_abstract_interface(CDRWriter.java:1118)
	>>	 at
com.ibm.CORBA.iiop.UtilDelegateImpl.writeAbstractObject(UtilDelegateImpl.java:483)
	>>	 at javax.rmi.CORBA.Util.writeAbstractObject(Util.java:148)
	>>	 at ...
	>>	 at
com.ibm.CORBA.iiop.ServerDelegate.dispatchInvokeHandler(ServerDelegate.java:623)
	>>	 at com.ibm.CORBA.iiop.ServerDelegate.dispatch(ServerDelegate.java:476)
	>>	 at com.ibm.rmi.iiop.ORB.process(ORB.java:513)
	>>	 at com.ibm.CORBA.iiop.ORB.process(ORB.java:1574)
	>>	 at com.ibm.rmi.iiop.Connection.respondTo(Connection.java:2845)
	>>	 at com.ibm.rmi.iiop.Connection.doWork(Connection.java:2718)
	>>	 at com.ibm.rmi.iiop.WorkUnitImpl.doWork(WorkUnitImpl.java:63)
	>>	 at com.ibm.ejs.oa.pool.PooledThread.run(ThreadPool.java:118)
	>>	 at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1604)
	>> SERVER (id=4773e3aa, host=myhost.mycompany.com) TRACE END.

Please can someone explain what I'm doing wrong? Thank you.
I'm using OpenJPA 1.2.3.

--
View this message in context: http://openjpa.208410.n2.nabble.com/Using-FetchPlan-setFetchBatchSize-feature-leads-to-java-io-NotSerializableException-tp6771824p6771824.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: Using FetchPlan.setFetchBatchSize() feature leads tojava.io.NotSerializableException

Posted by "M. Walter" <ma...@sbb.ch>.
Okay, using the method setFetchBatchSize(int size) works as desired but the
result is not serializable so an exception will occur after trying to send
the result to a remote client. The simple solution to this problem is: copy
the result list content to a new list and send the copy to the client.
That's it.

--
View this message in context: http://openjpa.208410.n2.nabble.com/Using-FetchPlan-setFetchBatchSize-feature-leads-to-java-io-NotSerializableException-tp6771824p6824148.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: Using FetchPlan.setFetchBatchSize() feature leads tojava.io.NotSerializableException

Posted by Miłosz Tylenda <mt...@o2.pl>.
Hi again,

Some database drivers might allow you to specify the default fetch size in connection URL or data source definition. For example, Oracle docs say they have a "defaultRowPrefetch" property for this. Of course, this is not specific to OpenJPA / JPA.

Greetings,
Milosz


> Hello,
> 
> It seems that setting openjpa.FetchBatchSize implicitly enables large result set support which is not suitable for your case.
> 
> However, chances are you can execute Statement.setFetchSize(int) by extending the DBDictionary you are using, although it needs some typing. As a guidance, see PostgresDictionary.decorate method. It creates a wrapped Connection, which in turn provides wrapped PreparedStatements where you can override methods like executeQuery and inject a call to setFetchSize. Or do it in prepareStatement method of your wrapped Connection.
> 
> Let us know how it goes.
> 
> Cheers,
> Milosz
> 
> > How do I set fetch size in JPA? I would like the cursor to read 2000 rows at
> > once to speed up entity generation. Thanks for help!
> > 
> > --
> > View this message in context: http://openjpa.208410.n2.nabble.com/Using-FetchPlan-setFetchBatchSize-feature-leads-to-java-io-NotSerializableException-tp6771824p6782493.html
> > Sent from the OpenJPA Users mailing list archive at Nabble.com.
> > 
> 

Re: Using FetchPlan.setFetchBatchSize() feature leads tojava.io.NotSerializableException

Posted by Miłosz Tylenda <mt...@o2.pl>.
Hello,

It seems that setting openjpa.FetchBatchSize implicitly enables large result set support which is not suitable for your case.

However, chances are you can execute Statement.setFetchSize(int) by extending the DBDictionary you are using, although it needs some typing. As a guidance, see PostgresDictionary.decorate method. It creates a wrapped Connection, which in turn provides wrapped PreparedStatements where you can override methods like executeQuery and inject a call to setFetchSize. Or do it in prepareStatement method of your wrapped Connection.

Let us know how it goes.

Cheers,
Milosz

> How do I set fetch size in JPA? I would like the cursor to read 2000 rows at
> once to speed up entity generation. Thanks for help!
> 
> --
> View this message in context: http://openjpa.208410.n2.nabble.com/Using-FetchPlan-setFetchBatchSize-feature-leads-to-java-io-NotSerializableException-tp6771824p6782493.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
> 

Re: Using FetchPlan.setFetchBatchSize() feature leads to java.io.NotSerializableException

Posted by Rick Curtis <cu...@gmail.com>.
For giggles, try this...
- Set the FetchBatchSize to 2000
- Execute your query
- Once you get the result back, iterate over the entire list before you send
it out to your client.

On Mon, Sep 12, 2011 at 2:17 AM, M. Walter <ma...@sbb.ch> wrote:

> How do I set fetch size in JPA? I would like the cursor to read 2000 rows
> at
> once to speed up entity generation. Thanks for help!
>
> --
>
-- 
*Rick Curtis*

Re: Using FetchPlan.setFetchBatchSize() feature leads to java.io.NotSerializableException

Posted by "M. Walter" <ma...@sbb.ch>.
How do I set fetch size in JPA? I would like the cursor to read 2000 rows at
once to speed up entity generation. Thanks for help!

--
View this message in context: http://openjpa.208410.n2.nabble.com/Using-FetchPlan-setFetchBatchSize-feature-leads-to-java-io-NotSerializableException-tp6771824p6782493.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: Using FetchPlan.setFetchBatchSize() feature leads to java.io.NotSerializableException

Posted by "M. Walter" <ma...@sbb.ch>.
Okay thanks. What I was trying to do was setting the fetch size like in
java.sql.ResultSet so rows aren't read one row at a time but many rows at a
time instead. We experienced a higher performance executing a query with
JDBC and using the fetch size feature. Without fetch size the JDBC query was
as fast as the JPA query. In other words setting the fetch size in JDBC can
speed up queries so JDBC is faster than JPA. So I searched the OpenJPA
documentation for how to set the fetch size and thought
FetchPlan.setFetchBatchSize() is what I need. But maybe this is something
different? Isn't it possible to set the fetch size in OpenJPA 1.2.3?

--
View this message in context: http://openjpa.208410.n2.nabble.com/Using-FetchPlan-setFetchBatchSize-feature-leads-to-java-io-NotSerializableException-tp6771824p6772248.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: Using FetchPlan.setFetchBatchSize() feature leads to java.io.NotSerializableException

Posted by Rick Curtis <cu...@gmail.com>.
> I was very astonished getting a
QueryCacheStoreQuery$CachingResultObjectProvider object as result.
I don't think that is quite the case.... You're getting a List
implementation back, but under the covers OpenJPA is hiding this
CachingResultObjectProvider.

> So what is going on here? I don't understand. Do I have to convert
something manually?
I spoke with Mike a little about this one, and I don't think what you are
trying to do is going to work. Setting the fetch batch size to a value
greater than zero means that OpenJPA will return you a result that will
stream results as they are requested.[1] This works fine when you are
processing a result set locally... when you try to stream this result out to
a remote client, OpenJPA doesn't have the ability to request additional data
from a remote client.

I'd recommend getting rid of the fetch batch size configuration.

Thanks,
Rick

[1]
http://openjpa.apache.org/builds/latest/docs/manual/manual.html#ref_guide_dbsetup_lrs

On Thu, Sep 8, 2011 at 9:45 AM, M. Walter <ma...@sbb.ch> wrote:

> Yes the problem only occurs if I set the fetch batch size.
>
> I was very astonished getting a
> QueryCacheStoreQuery$CachingResultObjectProvider object as result. I would
> have expected an OpenJPA implementation of the List interface containing my
> entities...
>
> So what is going on here? I don't understand. Do I have to convert
> something
> manually?
>
> --
>



-- 
*Rick Curtis*

Re: Using FetchPlan.setFetchBatchSize() feature leads to java.io.NotSerializableException

Posted by "M. Walter" <ma...@sbb.ch>.
Yes the problem only occurs if I set the fetch batch size.

I was very astonished getting a
QueryCacheStoreQuery$CachingResultObjectProvider object as result. I would
have expected an OpenJPA implementation of the List interface containing my
entities...

So what is going on here? I don't understand. Do I have to convert something
manually?

--
View this message in context: http://openjpa.208410.n2.nabble.com/Using-FetchPlan-setFetchBatchSize-feature-leads-to-java-io-NotSerializableException-tp6771824p6772133.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: Using FetchPlan.setFetchBatchSize() feature leads to java.io.NotSerializableException

Posted by Rick Curtis <cu...@gmail.com>.
Does this problem only occur when you set the fetch batch size? I tried
recreating this problem on trunk with a simple unit test where I serialized
a result that came from a cached query and I am unable to see the same
behavior. If I get some time this am I'll give it a shot on 1.2.x.

Thanks,
Rick

On Thu, Sep 8, 2011 at 8:33 AM, M. Walter <ma...@sbb.ch> wrote:

> In my code I would like to set the fetch batch size in order to "speed up"
> loading entities:
>
> final OpenJPAQuery ojpaQuery =
> OpenJPAPersistence.cast(em.createNamedQuery(myNiceQuery));
> ojpaQuery.getFetchPlan().setFetchBatchSize(2000);
> final List result = ojpaQuery.getResultList();
>
> The result list should be sent to a RCP client.
> Now I wonder why I get java.io.NotSerializableException on the client side
> using this feature:
>
> Exception in thread "P=573122:O=0:CT" java.rmi.MarshalException: CORBA
> BAD_PARAM 0x4f4d0006 Maybe; nested exception is:
>        java.io.NotSerializableException:
>        >> SERVER (id=4773e3aa, host=myhost.mycompany.com) TRACE START:
>        >>    org.omg.CORBA.BAD_PARAM:
>
> org.apache.openjpa.datacache.QueryCacheStoreQuery$CachingResultObjectProvider
> is not serializable  vmcid: OMG  minor code: 6 completed: Maybe
>        >>       at
> com.ibm.rmi.util.Utility.throwNotSerializableForCorba(Utility.java:1661)
>        >>       at
> com.ibm.rmi.io.IIOPOutputStream.writeValueType(IIOPOutputStream.java:1142)
>        >>       at
>
> com.ibm.rmi.io.IIOPOutputStream.writeObjectField(IIOPOutputStream.java:1082)
>        >>       at
>
> com.ibm.rmi.io.IIOPOutputStream.outputClassFields(IIOPOutputStream.java:1013)
>        >>       at
> com.ibm.rmi.io.IIOPOutputStream.outputObject(IIOPOutputStream.java:997)
>        >>       at
>
> com.ibm.rmi.io.IIOPOutputStream.continueSimpleWriteObject(IIOPOutputStream.java:484)
>        >>       at
>
> com.ibm.rmi.io.IIOPOutputStream.simpleWriteObjectLoop(IIOPOutputStream.java:464)
>        >>       at
>
> com.ibm.rmi.io.IIOPOutputStream.simpleWriteObject(IIOPOutputStream.java:528)
>        >>       at
> com.ibm.rmi.io.ValueHandlerImpl.writeValue(ValueHandlerImpl.java:168)
>        >>       at
> com.ibm.rmi.iiop.CDRWriter.write_value(CDRWriter.java:1195)
>        >>       at
> com.ibm.rmi.iiop.CDRWriter.write_value(CDRWriter.java:1213)
>        >>       at
> com.ibm.rmi.iiop.CDRWriter.write_abstract_interface(CDRWriter.java:1118)
>        >>       at
>
> com.ibm.CORBA.iiop.UtilDelegateImpl.writeAbstractObject(UtilDelegateImpl.java:483)
>        >>       at javax.rmi.CORBA.Util.writeAbstractObject(Util.java:148)
>        >>       at ...
>        >>       at
>
> com.ibm.CORBA.iiop.ServerDelegate.dispatchInvokeHandler(ServerDelegate.java:623)
>        >>       at
> com.ibm.CORBA.iiop.ServerDelegate.dispatch(ServerDelegate.java:476)
>        >>       at com.ibm.rmi.iiop.ORB.process(ORB.java:513)
>        >>       at com.ibm.CORBA.iiop.ORB.process(ORB.java:1574)
>        >>       at
> com.ibm.rmi.iiop.Connection.respondTo(Connection.java:2845)
>        >>       at com.ibm.rmi.iiop.Connection.doWork(Connection.java:2718)
>        >>       at
> com.ibm.rmi.iiop.WorkUnitImpl.doWork(WorkUnitImpl.java:63)
>        >>       at
> com.ibm.ejs.oa.pool.PooledThread.run(ThreadPool.java:118)
>        >>       at
> com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1604)
>        >> SERVER (id=4773e3aa, host=myhost.mycompany.com) TRACE END.
>
> Please can someone explain what I'm doing wrong? Thank you.
> I'm using OpenJPA 1.2.3.
>



-- 
*Rick Curtis*