views:

325

answers:

2

I have a strange problem, that is causing me some grief. If the following jar is in my classpath:

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>org.hibernate.ejb</artifactId>
<version>3.3.2.GA</version>
</dependency>

My JNDI lookup for my datasource returns null. Here is the basic code I am using to do the lookup:

InitialDirContext ctx = new InitialDirContext(env);
DataSource dataSource = (DataSource)ctx.lookup("java:dataContent");

Otherwise, the DataSource returns fine from the context. Unfortunately, I need the jar in order to avoid ClassCastExceptions within Jboss 4.2.2.

Any help is appreciated.

<datasources>
<local-tx-datasource>
<jndi-name>dataContent</jndi-name>
<connection-url>jdbc:oracle:thin:@server.net:1521:XXX</connection-url>
<min-pool-size>1</min-pool-size>
<max-pool-size>5</max-pool-size>
<user-name>dbuser</user-name>
<valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleValidConnectionChecker</valid-connection-checker-class-name>
<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>
<password>dbpasswd</password>
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
</local-tx-datasource>
</datasources>
A: 

As I remeber JBoss 4.2 is EJB3/JPA compatable and thus the hibernate persistence implementation should only be used for compilation. The following maven dependency should accomplish this:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>org.hibernate.ejb</artifactId>
    <version>3.3.2.GA</version>
    <scope>provided</scope>
</dependency>

If you are only using the JPA part you might further trim down by only depending on the javax.persistence api.

Lars Tackmann
A: 

Looks like including that dependency is bringing in transitively some other jars too. Make sure your application does not package JBoss specific jar files. In this case, I think it might be the presence of jboss-common-core.jar in your application which might be resulting in this issue. Remove that jar (and any other JBoss specific jar files) - you can add a in the maven dependency.

jaikiran