I'm sorry, I misunderstood the exception. The workaround won't work as the
problem is related to the fact that AbstractScope is not serializable, nor
does it define a default constructor. So, the only workaround right now is
probably not to serialise DSLContext, but Configuration.

In fact, I don't think that DefaultDSLContext should be Serializable in the
first place. This doesn't really make any sense, since most Scopes aren't
Serializable either...

2015-06-16 16:20 GMT+02:00 Lukas Eder <[email protected]>:

> I see. I overlooked the fact that you were serialising the
> DefaultDSLContext, not the DefaultConfiguration. It's true, this type is
> currently not implemented correctly according to the contract of
> java.io.Serializable. I've created an issue for this:
> https://github.com/jOOQ/jOOQ/issues/4393
>
> A workaround would be to implement the following subclass:
>
> public class MyDSLContext extends DefaultDSLContext {
>     public MyDSLContext() {
>         super(new DefaultConfiguration());
>     }
>
>     // ...
> }
>
>
> Or not to serialise the DSLContext, but the Configuration instead.
>
> We'll fix this ASAP. Thanks for reporting!
>
> Cheers,
> Lukas
>
> 2015-06-11 21:47 GMT+02:00 Daniel Barbato <[email protected]>:
>
>> Stripping the code back as much as I can, here's something that should be
>> reproducible:
>>
>> import org.jooq.impl.DefaultDSLContext;
>> import org.springframework.beans.factory.annotation.Autowired;
>> import org.springframework.test.context.ContextConfiguration;
>> import
>> org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
>> import org.testng.annotations.Test;
>>
>> import backtype.storm.utils.Utils;
>>
>> @ContextConfiguration(locations = { "classpath:application-context.xml" })
>> public class SerializationTest extends AbstractTestNGSpringContextTests {
>>
>>     @Autowired
>>     private DefaultDSLContext jooq;
>>
>>     @Test
>>     public void serializeDefaultDSL() {
>>         final byte[] serializedJooq = Utils.serialize(jooq);
>>         Utils.deserialize(serializedJooq);
>>     }
>> }
>>
>> The Utils.serialize and deserialize is basically a call through to :
>>
>>   try {
>>             ByteArrayOutputStream bos = new ByteArrayOutputStream();
>>             ObjectOutputStream oos = new ObjectOutputStream(bos);
>>             oos.writeObject(object);
>>             oos.close();
>>             return bos.toByteArray();
>>         } catch (IOException e) {
>>             throw new RuntimeException(e);
>>         }
>>
>> and
>>
>>    try {
>>             ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
>>             ObjectInputStream ois = new ObjectInputStream(bis);
>>             Object ret = ois.readObject();
>>             ois.close();
>>             return ret;
>>         } catch(IOException ioe) {
>>             throw new RuntimeException(ioe);
>>         } catch(ClassNotFoundException e) {
>>             throw new RuntimeException(e);
>>         }
>>
>> with the line
>> Object ret = ois.readObject();
>> throwing  java.io.InvalidClassException: org.jooq.impl.DefaultDSLContext;
>> no valid constructor
>>
>> Here's the (very) stripped back snippet from the application context
>>     <bean id="dsl" class="org.jooq.impl.DefaultDSLContext">
>>         <constructor-arg ref="config" />
>>     </bean>
>>     <bean class="org.jooq.impl.DefaultConfiguration" name="config">
>>         <constructor-arg index="0" ref="connectionProvider" />
>>         <constructor-arg index="1"><null /></constructor-arg>
>>         <constructor-arg index="2"><null /></constructor-arg>
>>         <constructor-arg index="3"><null /></constructor-arg>
>>         <constructor-arg index="4"><null /></constructor-arg>
>>         <constructor-arg index="5"><value
>> type="org.jooq.SQLDialect">MYSQL</value></constructor-arg>
>>         <constructor-arg index="6"><null /></constructor-arg>
>>         <constructor-arg index="7"><null /></constructor-arg>
>>     </bean>
>>     <bean class="org.jooq.impl.DataSourceConnectionProvider"
>> name="connectionProvider">
>>         <constructor-arg ref="lazyConnectionDataSource" />
>>     </bean>
>>     <bean id="lazyConnectionDataSource"
>> class="org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy">
>>         <constructor-arg ref="dataSource"/>
>>     </bean>
>>     <bean id="dataSource"
>> class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
>>         <property name="driverClass" value="com.mysql.jdbc.Driver" />
>>         <property name="jdbcUrl" value="jdbc:mysql://127.0.0.1:3306/test"
>> />
>>         <property name="user" value="root" />
>>         <property name="password" value="" />
>>         <property name="acquireIncrement" value="3"/>
>>         <property name="initialPoolSize" value="5"/>
>>         <property name="maxIdleTime" value="600"/>
>>         <property name="maxPoolSize" value="5"/>
>>         <property name="minPoolSize" value="5"/>
>>         <property name="testConnectionOnCheckin" value="true"/>
>>     </bean>
>>
>> And here's the storm maven dependencies:
>>
>>         <dependency>
>>             <artifactId>storm-core</artifactId>
>>             <groupId>org.apache.storm</groupId>
>>             <version>0.9.4</version>
>>             <scope>provided</scope>
>>         </dependency>
>>
>> Thanks
>>
>>
>> On Thursday, 11 June 2015 13:27:48 UTC-4, Lukas Eder wrote:
>>
>>> Interesting, our java Serialization integration tests work smoothly. Is
>>> Storm using standard Java Serialization? Could you perhaps show a minimal
>>> example that reproduces this behaviour on your side? Here's our current
>>> integration test, for the record:
>>>
>>>     public void testSerialisation() throws Exception {
>>>         jOOQAbstractTest.reset = false;
>>>
>>>         Select<A> q =
>>> create().selectFrom(TAuthor()).orderBy(TAuthor_LAST_NAME());
>>>
>>>         // Serialising the unexecuted query
>>>         //
>>> ---------------------------------------------------------------------
>>>         q = runSerialisation(q);
>>>
>>>         try {
>>>             q.execute();
>>>             fail();
>>>         } catch (DetachedException expected) {}
>>>
>>>         // Serialising the executed query
>>>         //
>>> ---------------------------------------------------------------------
>>>         create().attach(q);
>>>         assertEquals(2, q.execute());
>>>         assertEquals("Coelho", q.getResult().getValue(0,
>>> TAuthor_LAST_NAME()));
>>>         assertEquals("Orwell", q.getResult().getValue(1,
>>> TAuthor_LAST_NAME()));
>>>
>>>         q = runSerialisation(q);
>>>         assertEquals("Coelho", q.getResult().getValue(0,
>>> TAuthor_LAST_NAME()));
>>>         assertEquals("Orwell", q.getResult().getValue(1,
>>> TAuthor_LAST_NAME()));
>>>
>>>         Result<A> result = q.getResult();
>>>         result = runSerialisation(result);
>>>         assertEquals("Coelho", result.getValue(0, TAuthor_LAST_NAME()));
>>>         assertEquals("Orwell", result.getValue(1, TAuthor_LAST_NAME()));
>>>
>>>         try {
>>>             result.get(1).setValue(TAuthor_FIRST_NAME(), "Georgie");
>>>             result.get(1).store();
>>>             fail();
>>>         } catch (DetachedException expected) {}
>>>
>>>         create().attach(result);
>>>         assertEquals(1, result.get(1).store());
>>>         assertEquals("Georgie", create()
>>>                 .fetchOne(TAuthor(), TAuthor_LAST_NAME().equal("Orwell"))
>>>                 .getValue(TAuthor_FIRST_NAME()));
>>>
>>>         // [#1191] Check execution capabilities with new features in
>>> ExecuteListener
>>>         ConnectionProviderListener.c =
>>> create().configuration().connectionProvider().acquire();
>>>         try {
>>>             DSLContext create = create(new ConnectionProviderListener());
>>>             q = create
>>>                     .selectFrom(TAuthor())
>>>                     .orderBy(TAuthor_LAST_NAME());
>>>             q = runSerialisation(q);
>>>             q.execute();
>>>
>>>             result = q.getResult();
>>>             result = runSerialisation(result);
>>>             assertEquals("Coelho", result.getValue(0,
>>> TAuthor_LAST_NAME()));
>>>             assertEquals("Orwell", result.getValue(1,
>>> TAuthor_LAST_NAME()));
>>>
>>>             result.get(1).setValue(TAuthor_FIRST_NAME(), "Gee-Gee");
>>>             result.get(1).store();
>>>         }
>>>         finally {
>>>
>>> create().configuration().connectionProvider().release(ConnectionProviderListener.c);
>>>             ConnectionProviderListener.c = null;
>>>         }
>>>
>>>         // [#1071] Check sequences
>>>         if (cSequences() == null) {
>>>             log.info("SKIPPING", "sequences test");
>>>         }
>>>         else {
>>>             Select<?> s;
>>>
>>>             s = create().select(SAuthorID().nextval(),
>>> SAuthorID().currval());
>>>             s = runSerialisation(s);
>>>         }
>>>     }
>>>
>>>     public static class ConnectionProviderListener extends
>>> DefaultExecuteListener {
>>>
>>>         /**
>>>          * Generated UID
>>>          */
>>>         private static final long serialVersionUID =
>>> 7399239846062763212L;
>>>
>>>         static Connection c;
>>>
>>>         @Override
>>>         public void start(ExecuteContext ctx) {
>>>             ctx.connectionProvider(new DefaultConnectionProvider(c));
>>>         }
>>>     }
>>>
>>>     @SuppressWarnings("unchecked")
>>>     private <Z> Z runSerialisation(Z value) throws Exception {
>>>         ByteArrayOutputStream out = new ByteArrayOutputStream();
>>>         ObjectOutputStream o = new ObjectOutputStream(out);
>>>         o.writeObject(value);
>>>         o.flush();
>>>
>>>         ByteArrayInputStream in = new
>>> ByteArrayInputStream(out.toByteArray());
>>>         ObjectInputStream i = new ObjectInputStream(in);
>>>         return (Z) i.readObject();
>>>     }
>>>
>>>
>>>
>>> 2015-06-11 17:41 GMT+02:00 Daniel Barbato <[email protected]>:
>>>
>>>> Hi,
>>>>
>>>> I'm needing to run JOOQ inside a storm cluster. Storm requires that all
>>>> classes are fully serializable. When attempting to deserialize
>>>> DefaultDSLContext I get the following error:
>>>>
>>>> java.lang.RuntimeException: java.io.InvalidClassException:
>>>> org.jooq.impl.DefaultDSLContext; no valid constructor
>>>>     at
>>>> backtype.storm.serialization.DefaultSerializationDelegate.deserialize(DefaultSerializationDelegate.java:56)
>>>> ~[storm-core-0.9.4.jar:0.9.4] ...
>>>>
>>>> I believe that this is due to org.jooq.impl.AbstractScope vontaining
>>>> state and not having a no-args constructor while not implementing
>>>> Serializable.
>>>>
>>>> I haven't looked through other class files to see if this is the case
>>>> elsewhere, I also couldn't see anyone else reporting the issue.
>>>>
>>>> Is there a known work around, other than using a third party
>>>> serialization tool?
>>>>
>>>> Thanks
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "jOOQ User Group" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to [email protected].
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>>  --
>> You received this message because you are subscribed to the Google Groups
>> "jOOQ User Group" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups "jOOQ 
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to