0 Replies Latest reply on May 4, 2013 10:26 AM by David Modino de la Pisa

    jndi datasource jboss Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

    David Modino de la Pisa Newbie

      Hi,

       

      I'm using JNDI + Hibernate + JBoss EAP 6.0; and I'm getting that error when I call to the method of "Managed Bean". I've followed the code statements in my code. Until Finally I've found the line that it throws that error. It's marked in bold.

       

      private static void openSessionFactory() {

                          Configuration configuration = new Configuration();

                          configuration.configure();

                          ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();

        // Create the session factory object to connect to the DataSource using JNDI defined in the file 'hibernate-cfg.xml' 

                          sessionFactory = configuration.buildSessionFactory(serviceRegistry);

        logger.info("Creating session factory");

                }


      In the other hand, I've checked the configuration files of the JBoss server "standalone.xml"

       

      <datasources>

                      <datasource jta="true" jndi-name="java:jboss/datasources/MySQLDS" pool-name="MySQLDS" enabled="true" use-java-context="true" use-ccm="true">

                          <connection-url>jdbc:mysql://localhost:3306/test</connection-url>

                          <driver>mysql</driver>

                          <transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>

                          <pool>

                              <min-pool-size>10</min-pool-size>

                              <max-pool-size>100</max-pool-size>

                              <prefill>true</prefill>

                              <use-strict-min>false</use-strict-min>

                              <flush-strategy>FailingConnectionOnly</flush-strategy>

                          </pool>

                          <security>

                              <user-name>root</user-name>

                          </security>

                          <statement>

                              <prepared-statement-cache-size>32</prepared-statement-cache-size>

                          </statement>

                      </datasource>

                      <datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true">

                          <connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1</connection-url>

                          <driver>h2</driver>

                          <security>

                              <user-name>test</user-name>

                              <password></password>

                          </security>

                      </datasource>

                      <drivers>

                          <driver name="mysql" module="com.mysql.jdbc"/>

                          <driver name="h2" module="com.h2database.h2">

                              <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>

                          </driver>

                      </drivers>

                  </datasources>

       

      Finally, "module.xml" configuration file which is located in "com.mysql.jdbc.main" package and in the same directory I've added the driver of MySql "mysql-connector-java-5.1.24-bin.jar"

       

      <module xmlns="urn:jboss:module:1.1" name="com.mysql.jdbc">

          <resources>

              <resource-root path="mysql-connector-java-5.1.24-bin.jar"/>

              <!-- Insert resources here -->

          </resources>

          <dependencies>

              <module name="javax.api"/>

              <module name="javax.transaction.api"/>

          </dependencies>

      </module>

       

      In the "hibernate.cfg.xml" file:

       

      <hibernate-configuration>

          <session-factory>

              <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> 

              <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/test</property>

              <property name="hibernate.connection.username">root</property>

              <property name="hibernate.connection.password"></property>

              <property name="hibernate.connection.pool_size">10</property>

              <property name="show_sql">true</property>

              <property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>

              <property name="hibernate.current_session_context_class">thread</property>

                          <property name="dialect">org.hibernate.dialect.MySQLDialect</property>   

       

          <property name="hbm2ddl.auto">validate</property>

          <property name="hibernate.id.new_generator_mappings">true</property>

         

           <!--the mapping resources here -->



      </hibernate-configuration>

       

       

      So, Anybody, could tell me what I am doing wrong???

       

      If you need more information or something I've not talked about my code ask me please!

       

      Thanks in advance.