Skip to main content

Linking persistence to JNDI datasource ... ?

1 reply [Last post]
tsmets
Offline
Joined: 2005-05-04
Points: 0

I have created a project :
Maven / WAR / JPA2 (through hibernate) + Struts (no EJB, no EAR)
Then I created a JDBC Connection Pool to the HSQLDB (not an in-memory DB but a real one)
+ a JDBC Connection mapped on the Pool with a JNDI name like : jdbc/myDS

I then created a persitence.xml file in META-INF :

<persistence 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"
        version="2.0">
    <persistence-unit name="sample" transaction-type="RESOURCE_LOCAL" >
    <jta-data-source>jdbc/myDS</jta-data-source>
      <class>eu.myApp.to.ServiceProvider</class>
      <properties>
        <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" />
        <property name="hibernate.hbm2ddl.auto" value="validate" />
        <property name="hibernate.archive.autodetecion" value="hbm" />
        <property name="hibernate.show_sql" value="true" />
        <property name="hibernate.format_sql" value="true" />
       </properties>
    </persistence-unit>
</persistence>

and also (for God's sake) a glassfish-web.xml :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app error-url="">
  <resource-ref>
    <res-ref-name>jdbc/my</res-ref-name>
    <jndi-name>jdbc/myDS</jndi-name>
  </resource-ref>
</glassfish-web-app>

It always ends up with various exceptions like :

  1. Exception Description: Unable to acquire a connection from driver [null], user [null] and URL [null]. Verify that you have set the expected driver class and URL. Check your login, persistence.xml or sessions.xml resource. The jdbc.driver property should be set to a class that is compatible with your database platform
  2. Exception [EclipseLink-4021] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException Exception Description: Unable to acquire a connection from driver [null], user [null] and URL [null]. Verify that you have set the expected driver class and URL. Check your login, persistence.xml or sessions.xml resource. The jdbc.driver property should be set to a class that is compatible with your database platform

Not to mentionned that the connection parameters are ALL OK as I used the same to connect to the DB from the SwingManager.sh
Anybody to hint me into the right set up .... ?

Tx !

\T,

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
tsmets
Offline
Joined: 2005-05-04
Points: 0

One of the "funny" thing there is that if you ask GF to list the JNDI resource, it never mentions the DS ... which is supposedly JNDI published

Thomas-Lionel-Smets-MacBook-Pro:bin tsmets$ ./asadmin
Use "exit" to exit and "help" for online help.
asadmin> list-jndi-entries
jdbc: com.sun.enterprise.naming.impl.TransientContext
UserTransaction: com.sun.enterprise.transaction.TransactionNamingProxy$UserTransactionProxy
ejb: com.sun.enterprise.naming.impl.TransientContext
java:global: com.sun.enterprise.naming.impl.TransientContext
com.sun.enterprise.container.common.spi.util.InjectionManager: com.sun.enterprise.container.common.impl.util.InjectionManagerImpl
Command list-jndi-entries executed successfully.

Has this something to do with my issue ... ?

\T,

--- Edited :
This is explained by the fact that the command is not recursive :

asadmin> list-jndi-entries --context jdbc
__default: org.glassfish.javaee.services.ResourceProxy
__TimerPool: org.glassfish.javaee.services.ResourceProxy
myDS: org.glassfish.javaee.services.ResourceProxy
Command list-jndi-entries executed successfully.

But I still don't know why I cannot use my DataSource :(