<p>I'm trying to access a data source that is defined within a web container (JBoss) from a fat client outside the container.</p>

<p>I've decided to look up the data source through JNDI. Actually, my persistence framework (Ibatis) does this.</p>

<p>When performing queries I always end up getting this error:</p>

<pre><code>java.lang.IllegalAccessException: Method=public abstract java.sql.Connection java.sql.Statement.getConnection() throws java.sql.SQLException does not return Serializable 

Stacktrace:
org.jboss.resource.adapter.jdbc.remote.WrapperDataSourceService.doStatementMethod(WrapperDataSourceS
ervice.java:411),
org.jboss.resource.adapter.jdbc.remote.WrapperDataSourceService.invoke(WrapperDataSourceService.java
:223),
sun.reflect.GeneratedMethodAccessor106.invoke(Unknown Source),
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25),
java.lang.reflect.Method.invoke(Method.java:585),
org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155),
org.jboss.mx.server.Invocation.dispatch(Invocation.java:94),
org.jboss.mx.server.Invocation.invoke(Invocation.java:86),
org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264),
org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659),
</code></pre>

<p>My Datasource:</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;datasources&gt;
  &lt;local-tx-datasource&gt;
        &lt;jndi-name&gt;jdbc/xxxxxDS&lt;/jndi-name&gt;
        &lt;connection-url&gt;jdbc:oracle:thin:@xxxxxxxxx:1521:xxxxxxx&lt;/connection-url&gt;
        &lt;use-java-context&gt;false&lt;/use-java-context&gt;
        &lt;driver-class&gt;oracle.jdbc.driver.OracleDriver&lt;/driver-class&gt;
        &lt;user-name&gt;xxxxxxxx&lt;/user-name&gt;
        &lt;password&gt;xxxxxx&lt;/password&gt;
        &lt;exception-sorter-class-name&gt;org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter&lt;/exception-sorter-class-name&gt;
        &lt;min-pool-size&gt;5&lt;/min-pool-size&gt;
        &lt;max-pool-size&gt;20&lt;/max-pool-size&gt;
    &lt;/local-tx-datasource&gt;
&lt;/datasources&gt;
</code></pre>

<p>Does anyone have a clue where this could come from? </p>

<p>Maybe someone even knows a better way how to achieve this.
Any hints are much appreciated!</p>

<p>Cheers,</p>

<p>Michael</p>

[{'answer_id': 39153, 'author': 'brabster', 'author_id': 2362, 'author_profile': 'https://Stackoverflow.com/users/2362', 'pm_score': 0, 'selected': False, 'text': "<p>I think the exception indicates that the SQLConnection object you're trying to retrieve doesn't implement the Serializable interface, so it can't be passed to you the way you asked for it.</p>\n\n<p>From the limited work I've done with JDNI, if you're asking for an object via JNDI it must be serializable. As far as I know, there's no way round that - if I think of a better way I'll post it up...</p>\n\n<p>OK, one obvious option is to provide a serializable object local to the datasource that uses it but doesn't have the datasource as part of its serializable object graph. The fat client could then look up that object and query it instead.</p>\n\n<p>Or create a (web?) service through which to access the datasource is governed - again your fat client would hit the service - this would probably be better encapsulated and more reuseable approach if those are concerns for you.</p>\n"}, {'answer_id': 39513, 'author': 'toolkit', 'author_id': 3295, 'author_profile': 'https://Stackoverflow.com/users/3295', 'pm_score': 1, 'selected': False, 'text': '<p>Not sure if this is the same issue?</p>\n\n<p><a href="http://www.redhat.com/docs/manuals/jboss/jboss-eap-4.2/doc/Server_Configuration_Guide/Connectors_on_JBoss-Configuring_JDBC_DataSources.html" rel="nofollow noreferrer">JBoss DataSource config</a></p>\n\n<blockquote>\n  <p>DataSource wrappers are not usable outside of the server VM</p>\n</blockquote>\n'}, {'answer_id': 39694, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': "<p>@toolkit:\nWell, not exactly. Since I can access the data source over JNDI, it is actually visible and thus usable. </p>\n\n<p>Or am I getting something totally wrong?</p>\n\n<p>@Brabster:\nI think you're on the right track. Isn't there a way to make the connection serializable? Maybe it's just a configuration issue...</p>\n"}, {'answer_id': 41611, 'author': 'brabster', 'author_id': 2362, 'author_profile': 'https://Stackoverflow.com/users/2362', 'pm_score': 1, 'selected': False, 'text': '<p>@Michael Well, java.sql.Connection is an Interface - it might technically be possible for the concrete implementation you\'re getting from JBoss to be Serializable - but I don\'t think you\'re really going to have any options you can use. If it was possible, it would probably be easy :)</p>\n\n<p>I think @toolkit might have said the right words with useable outside the VM - the JDBC drivers will be talking to native driver code running in the underlying OS I guess, so that might explain why you can\'t just pass a connection over the network elsewhere.</p>\n\n<p>My advice, (if you don\'t get any better advice!) would be to find a different approach - if you have access to locate the resource on the JBoss directory, maybe implement a proxy object that you can locate and obtain from the directory that allows you to use the connection remotely from your fat client. That\'s a design pattern called data transfer object I think <a href="http://en.wikipedia.org/wiki/Data_Transfer_Object" rel="nofollow noreferrer">Wikipedia entry</a></p>\n'}, {'answer_id': 42177, 'author': 'brabster', 'author_id': 2362, 'author_profile': 'https://Stackoverflow.com/users/2362', 'pm_score': 0, 'selected': False, 'text': '<p>I\'ve read up on Ibatis now - maybe you can make your implementations of Dao etc. Serializable, post them into your directory and so retrieve them and use them in your fat client? You\'d get reuse benefits out of that too.</p>\n\n<p>Here\'s an example of something looks similar for <a href="http://cwiki.apache.org/WICKET/ibatis.html" rel="nofollow noreferrer">Wicket</a></p>\n'}, {'answer_id': 55499, 'author': 'Tim Williscroft', 'author_id': 2789, 'author_profile': 'https://Stackoverflow.com/users/2789', 'pm_score': 0, 'selected': False, 'text': "<p>JBoss wraps up all DataSources with it's own ones.</p>\n\n<p>That lets it play tricks with autocommit to get the specified J2EE behaviour out of a JDBC connection. They are <em>mostly</em> serailizable. But you needn't trust them.</p>\n\n<p>I'd look carefully at it's wrappers.  I've written a surrogate for JBoss's J2EE wrappers wrapper for JDBC that works with OOCJNDI to get my DAO code unit test-able standalone.</p>\n\n<p></p>\n\n<p>You just wrap java.sql.Driver, point OOCJNDI at your class, and run in JUnit.</p>\n\n<p>The Driver wrapper can just directly create a SQL Driver and delegate to it.</p>\n\n<p>Return a java.sql.Connection wrapper of your own devising on Connect.</p>\n\n<p>A ConnectionWrapper can just wrap the Connection your Oracle driver gives you,\nand all it does special is set Autocommit true.</p>\n\n<p>Don't forget Eclipse can wrt delgates for you. Add a member you need to delegate to , then select it and right click, source -=>add delgage methods.  </p>\n\n<p>This is great when you get paid by the line ;-)</p>\n\n<p>Bada-bing, Bada-boom, JUnit out of the box J2EE testing.</p>\n\n<p>Your problem is probably amenable to the same thing, with JUnit crossed out and FatCLient written in an crayon.</p>\n\n<p>My FatClient uses RMI generated with xdoclet to talk to the J2EE server, so I don't have your problem.</p>\n"}]
['https://Stackoverflow.com/questions/39053', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']