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

    getting a JDBC connection through JNDI on JBoss 6.x


      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">




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

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





      my jboss standalone.xml file content :

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




















      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 !!