[jboss-user] [JNDI and Naming] - Reference cannot be cast to DataSource w/ standalone app client

Steve Maring do-not-reply at jboss.com
Tue Sep 20 08:35:24 EDT 2011


Steve Maring [http://community.jboss.org/people/stevemaring] created the discussion

"Reference cannot be cast to DataSource w/ standalone app client"

To view the discussion, visit: http://community.jboss.org/message/627473#627473

--------------------------------------------------------------
I am trying to unit test some JPA2 DAO classes I wrote using Maven.  The persistence.xml looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
    xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">

    <persistence-unit name="lifesmartEntityManager" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <non-jta-data-source>*MyDS*</non-jta-data-source>
        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
            <property name="hibernate.show-sql" value="true" />
        </properties>
    </persistence-unit>

</persistence>

I have deployed the DataSource to a running instance of AS 6.1.0.Final and confirmed that the global JNDIView has:

+- *MyDS* (class: javax.sql.DataSource)

When I try to run my tests, which rely on Hibernate EntityManager to lookup and associate the DataSource with the persistence-unit, I get:


08:05:12,185 ERROR [DatasourceConnectionProvider] Could not find datasource: *MyDS*
*java.lang.ClassCastException: javax.naming.Reference cannot be cast to javax.sql.DataSource*
        at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:75)
        at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:143)
        at org.hibernate.ejb.InjectionSettingsFactory.createConnectionProvider(InjectionSettingsFactory.java:51)
        at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:91)
        at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2833)
        at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2829)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1840)
        at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:902)
        at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:57)
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:48)


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:

08:25:34,525 ERROR [DatasourceConnectionProvider] Could not find datasource: *YourDS*
javax.naming.NameNotFoundException: *YourDS* not bound
        at org.jnp.server.NamingServer.getBinding(NamingServer.java:771)


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.  So far, nothing has helped.  My test classpath, at this point, contains these declared artifacts, and the dependencies declared in their poms:

slf4j-log4j12
testng
jnp-client
jboss-remoting
jbosssx-client
jboss-security-spi
hibernate-validator
jboss-logging
jboss-ejb3-vfs-spi
jboss-ejb3-core
jboss-kernel
jboss-dependency
jboss-classloading-vfs
jboss-classloading
jboss-classloader
jboss-service-binding-core
jboss-metadata-client
jboss-transaction-api_1.1_spec
jboss-jmx
jboss-integration
jboss-vfs
jboss-reflect
jboss-common-core
jboss-serialization
hibernate-jpa-2.0-api
hibernate-entitymanager


I am, perhaps, still missing an artifact?

-Steve Maring
Tampa, FL
--------------------------------------------------------------

Reply to this message by going to Community
[http://community.jboss.org/message/627473#627473]

Start a new discussion in JNDI and Naming at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2083]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20110920/0e219c8f/attachment-0001.html 


More information about the jboss-user mailing list