[jboss-user] Help with JNDI datasource for JPA?

Jari Fredriksson jarif at iki.fi
Wed Dec 10 10:29:52 EST 2008

> I'm trying to set up a JNDI datasource that will be used by a JPA
> application.  Everything seems to go along fine until the JPA system
> attempts to find the name to bind to.  Then I get the following exception:
> 13:41:11,144 ERROR [AbstractKernelController] Error installing to Start:
> name=persistence.unit:unitName=#punit state=Create
> javax.naming.NameNotFoundException: env not bound
> Here is my JNDI datasource definition:
> (I'm setting up the name as a "comp/env" in an attempt to be compatible
> with Jetty for development purposes.  If there's a better way, I'm all
> ears.)
> <datasources>
>     <local-tx-datasource>
>         <jndi-name>comp/env/salient/dataSource</jndi-name>
>         <connection-url>jdbc:mysql://localhost:3306/xxx</connection-url>
>         <driver-class>com.mysql.jdbc.Driver</driver-class>
>         <user-name>xxx</user-name>
>         <password>xxx</password>
>         <connection-property
> name="autoReconnect">true</connection-property>
>     </local-tx-datasource>
> </datasources>
> Here is my persistence unit definition for JPA:
>     <persistence-unit name="punit">
>         <jta-data-source>java:comp/env/salient/dataSource</jta-data-source>
>     </persistence-unit>
> Any thoughts?
> Thanks,
> Dave

Do it this way:


and in persistence unit

   <persistence-unit name="punit">

The key here is that "use-java-context" false.

More information about the jboss-user mailing list