<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="http://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    Reference cannot be cast to DataSource w/ standalone app client
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="http://community.jboss.org/people/stevemaring">Steve Maring</a> in <i>JNDI and Naming</i> - <a href="http://community.jboss.org/message/627473#627473">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>I am trying to unit test some JPA2 DAO classes I wrote using Maven.&#160; The persistence.xml looks like this:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier;">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</span></p><p><span style="font-family: courier new,courier;">&lt;persistence version="2.0"</span></p><p><span style="font-family: courier new,courier;"><span>&#160;&#160;&#160; xmlns="</span><a class="jive-link-external-small" href="http://java.sun.com/xml/ns/persistence" target="_blank">http://java.sun.com/xml/ns/persistence</a><span>" xmlns:xsi="</span><a class="jive-link-external-small" href="http://www.w3.org/2001/XMLSchema-instance" target="_blank">http://www.w3.org/2001/XMLSchema-instance</a><span>"</span></span></p><p><span style="font-family: courier new,courier;"><span>&#160;&#160;&#160; xsi:schemaLocation="</span><a class="jive-link-external-small" href="http://java.sun.com/xml/ns/persistence" target="_blank">http://java.sun.com/xml/ns/persistence</a><span> </span><a class="jive-link-external-small" href="http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" target="_blank">http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd</a><span>"&gt;</span></span></p><p>&#160;&#160;&#160; </p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160; &lt;persistence-unit name="lifesmartEntityManager" transaction-type="RESOURCE_LOCAL"&gt;</span></p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;</span></p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;non-jta-data-source&gt;<strong>MyDS</strong>&lt;/non-jta-data-source&gt;</span></p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;properties&gt;</span></p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" /&gt;</span></p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;property name="hibernate.show-sql" value="true" /&gt;</span></p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;/properties&gt;</span></p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160; &lt;/persistence-unit&gt;</span></p><p>&#160;&#160;&#160; </p><p><span style="font-family: courier new,courier;">&lt;/persistence&gt;</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I have deployed the DataSource to a running instance of AS 6.1.0.Final and confirmed that the global JNDIView has:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><span style="font-family: courier new,courier;">+- <strong>MyDS </strong>(class: javax.sql.DataSource)</span></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>When I try to run my tests, which rely on Hibernate EntityManager to lookup and associate the DataSource with the persistence-unit, I get:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier;">08:05:12,185 ERROR [DatasourceConnectionProvider] Could not find datasource: <strong>MyDS</strong></span></p><p><span style="font-family: courier new,courier;"><strong>java.lang.ClassCastException: javax.naming.Reference cannot be cast to javax.sql.DataSource</strong></span></p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:75)</span></p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:143)</span></p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; at org.hibernate.ejb.InjectionSettingsFactory.createConnectionProvider(InjectionSettingsFactory.java:51)</span></p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:91)</span></p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2833)</span></p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2829)</span></p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1840)</span></p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:902)</span></p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:57)</span></p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:48)</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I am certain that it is not truly a naming problem, because when I change the name to something bogus in the persistence.xml and run the test again, the error is different:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier;">08:25:34,525 ERROR [DatasourceConnectionProvider] Could not find datasource: <strong>YourDS</strong></span></p><p><span style="font-family: courier new,courier;">javax.naming.NameNotFoundException: <strong>YourDS</strong> not bound</span></p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; at org.jnp.server.NamingServer.getBinding(NamingServer.java:771)</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Some have suggested this is really a classpath issue and I have started adding standalone remote client oriented libs in a bit of a shotgun approach.&#160; So far, nothing has helped.&#160; My test classpath, at this point, contains these declared artifacts, and the dependencies declared in their poms:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier;">slf4j-log4j12</span></p><p><span style="font-family: courier new,courier;">testng</span></p><p><span style="font-family: courier new,courier;">jnp-client</span></p><p><span style="font-family: courier new,courier;">jboss-remoting</span></p><p><span style="font-family: courier new,courier;">jbosssx-client</span></p><p><span style="font-family: courier new,courier;">jboss-security-spi</span></p><p><span style="font-family: courier new,courier;">hibernate-validator</span></p><p><span style="font-family: courier new,courier;">jboss-logging</span></p><p><span style="font-family: courier new,courier;">jboss-ejb3-vfs-spi</span></p><p><span style="font-family: courier new,courier;">jboss-ejb3-core</span></p><p><span style="font-family: courier new,courier;">jboss-kernel</span></p><p><span style="font-family: courier new,courier;">jboss-dependency</span></p><p><span style="font-family: courier new,courier;">jboss-classloading-vfs</span></p><p><span style="font-family: courier new,courier;">jboss-classloading</span></p><p><span style="font-family: courier new,courier;">jboss-classloader</span></p><p><span style="font-family: courier new,courier;">jboss-service-binding-core</span></p><p><span style="font-family: courier new,courier;">jboss-metadata-client</span></p><p><span style="font-family: courier new,courier;">jboss-transaction-api_1.1_spec</span></p><p><span style="font-family: courier new,courier;">jboss-jmx</span></p><p><span style="font-family: courier new,courier;">jboss-integration</span></p><p><span style="font-family: courier new,courier;">jboss-vfs</span></p><p><span style="font-family: courier new,courier;">jboss-reflect</span></p><p><span style="font-family: courier new,courier;">jboss-common-core</span></p><p><span style="font-family: courier new,courier;">jboss-serialization</span></p><p><span style="font-family: courier new,courier;">hibernate-jpa-2.0-api</span></p><p><span style="font-family: courier new,courier;">hibernate-entitymanager</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I am, perhaps, still missing an artifact?</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>-Steve Maring</p><p>Tampa, FL</p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Reply to this message by <a href="http://community.jboss.org/message/627473#627473">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in JNDI and Naming at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2083">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>