0 Replies Latest reply on Dec 12, 2014 9:28 AM by erico.mtx

    getting a JDBC connection through JNDI on JBoss 6.x

    erico.mtx

      I have an application using JSF (primefaces 4) + JPA on Jboss 6.1

      All my DB mapping is made through annotation and my DAOs extend a generic DAO configured by a Factory Producer

      Factory Producer I declare my Entity Manager that will be injected in the my DAOs

      I need to call a procedure and leave the app free turning it back to the screen

      For that I have used an async ajax call in JSF along with Thread . In my Thread I am trying to call the procedure call through run method

      My problem is this .. My Thread is used as follows :

      Thread pdft = new Thread(new  MyThread());

      Doing this I leave JSF scope ... and all my annotations injections stop working

      So I don´t  get a valid Entity Manager ... etc ...

      I am trying to get a valid java.sql.Connection pointing to my app persistence.xml

      for this I have tried the following :

      ctx = new InitialContext();

      DataSource ds = (DataSource) ctx.lookup("java:/testeDS");

      conn = ds.getConnection();

       

       

      It is not working . The connection is instantiated but it is not ok ... It that the table from the query doesn´t exist ( it does ... it is working properly )  

       

      my app persitence.xml file content :

       

      <?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="teste" transaction-type="RESOURCE_LOCAL">

              <provider>org.hibernate.ejb.HibernatePersistence</provider>

              <jta-data-source>java:/testDS</jta-data-source>

              <properties>

                  <property name="hibernate.show_sql" value="false" />

                  <property name="hibernate.format_sql" value="false" />

              </properties>

          </persistence-unit>

      </persistence>

       

      my jboss standalone.xml file content :

      <datasource jndi-name="java:/testDS" pool-name="testeDSPool" enabled="true" use-ccm="true">

                  <connection-url>jdbc:oracle:thin:@xx.x.x.xx:1111:DB</connection-url>

                  <driver>OracleDriver</driver>

                      <pool>

                          <min-pool-size>1</min-pool-size>

                          <max-pool-size>50</max-pool-size>

                      </pool>

                      <security>

                          <user-name>usuario</user-name>

                          <password>senha</password>

                      </security>

                      <validation>

                          <validate-on-match>false</validate-on-match>

                          <background-validation>false</background-validation>

                      </validation>

                      <statement>

                          <share-prepared-statements>false</share-prepared-statements>

                      </statement>

          </datasource>

       

      I am stuck on this for the all week googling for codes but with out success

      I am posting this question here because all the samples that I have got on the web are related to JNDI and JDBC but again none worked

      So I thought that some one that uses JBoss 6.x would give some help on the setting code according to my environment

       

      Thks !!

      Érico