0 Replies Latest reply on Feb 6, 2014 11:17 PM by rjiang21

    JPA+mysql No suitable driver found when deployed to JBoss 7.1.1

    rjiang21

      This is the question I asked at stackoverflow, unfortunately, no solution so far. So I paste my question here.

      I am using JPA + Hibernate provider + MySQL in my spring mvc project.

      These are the tests I did so far.

      1. I deploy it to Tomcat, it executes with no problem.

      2. Run as a java console, works fine too.

      Then when I move it to JBoss 7.1.1. it throws me No suitable Driver found exception.

      java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/test

      So I narrow this down to JBoss.

      This is my persistence.xml

      <?xml version="1.0" encoding="UTF-8"?>
      <persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
        
      <persistence-unit name="personDB">
        
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
        
      <class>com.springapp.modlels.OfficeEntity</class>
        
      <properties>
        
      <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/test"/>
        
      <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
        
      <property name="hibernate.connection.username" value="root"/>
        
      <property name="hibernate.connection.password" value="9ijn)OKM"/>
        
      <property name="hibernate.show_sql" value="true"/>
        
      <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
        
      </properties>
        
      </persistence-unit>
      </persistence>

      and this is my calling code simple and easy

      EntityManagerFactory emf = Persistence.createEntityManagerFactory("personDB");
        
      EntityManager mgr = emf.createEntityManager();
        mgr
      .getTransaction().begin();
        
      OfficeEntity officeEntity = new OfficeEntity();
        officeEntity
      .setOfficeName("test");
        mgr
      .persist(officeEntity);
        mgr
      .getTransaction().commit();

      It looks like the JBoss cannot find the suitable driver when getTransaction() get called. And my driver and provider class are

      <dependency>
        
      <groupId>org.hibernate</groupId>
        
      <artifactId>hibernate-entitymanager</artifactId>
        
      <version>4.2.1.Final</version>
        
      </dependency>
        
      <dependency>
        
      <groupId>mysql</groupId>
        
      <artifactId>mysql-connector-java</artifactId>
        
      <version>5.1.21</version>
        
      </dependency>

      Also someone suggested me to install the JDBC driver to JBoss. This is what i did in \modules\com\mysql\main, I copied mysql-connector-java-5.1.21.jar here and created the module.xml,

      <module xmlns="urn:jboss:module:1.0" name="com.mysql">
       
      <resources>
        
      <resource-root path="mysql-connector-java-5.1.21.jar"/>
       
      </resources>
       
      <dependencies>
        
      <module name="javax.api"/>
       
      </dependencies>
      </module>

      I also modified the \standalone\configuration\standalone.xml

      <datasources>
        
      <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>sa</user-name>
        
      <password>sa</password>
        
      </security>
        
      </datasource>
        
      <datasource jta="false" jndi-name="java:/mysqldb" pool-name="my_mysl" enabled="true" use-ccm="false">
        
      <connection-url>jdbc:mysql://localhost:3306/test</connection-url>
        
      <driver-class>com.mysql.jdbc.Driver</driver-class>
        
      <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>
        
      </pool>
        
      <security>
        
      <user-name>root</user-name>
        
      <password>9ijn)OKM</password>
        
      </security>
        
      <validation>
        
      <validate-on-match>false</validate-on-match>
        
      <background-validation>false</background-validation>
        
      </validation>
        
      <statement>
        
      <prepared-statement-cache-size>32</prepared-statement-cache-size>
        
      <share-prepared-statements>false</share-prepared-statements>
        
      </statement>
        
      </datasource>
        
      <drivers>
        
      <driver name="h2" module="com.h2database.h2">
        
      <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
        
      </driver>
        
      <driver name="mysql" module="com.mysql"/>
        
      </drivers>
        
      </datasources>

      And I also tested the datasource in JBoss admin console and it connects succesfully. But I am sorry, by adding this, it still shows me the same exception.

       

      Please help, Thank you.