简体   繁体   中英

Error creating Session: org.hibernate.HibernateException: Specified JDBC Driver com.mysql.jdbc.Driver class not found

using Jboss 7.1.1. I have connection to the DB out of localhost:9990/console. The Connection Test is correct. But when i try to put something into the DB an exception occurs:

Error creating Session: org.hibernate.HibernateException: Specified JDBC Driver com.mysql.jdbc.Driver class not found

my hibernate.cfg.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
 "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.password">root</property>
    <property   name="hibernate.connection.url">
     jdbc:mysql://localhost:3306/test</property>
    <property name="hibernate.connection.username">root</property>
    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name="show_sql">true</property>
    <property name="hbm2ddl.auto">create</property>

     <mapping resource="MyApp/WebApp/model/Member.hbm.xml"/>
</session-factory>

My Session factory:

static
{
    try
    {
        Configuration configuration = new Configuration().configure();
        serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
        sessionFactory = configuration.buildSessionFactory(serviceRegistry);
    }
    catch (HibernateException he)
    {
        System.err.println("Error creating Session: " + he);
        throw new ExceptionInInitializerError(he);
    }

inside JBOSSHOME/modules/com/mysql/main are the module.xml and the connector. i dont need to have the connector inside the WEB-INFlib folder..or do I?

any ideas??

Ok ..i found a solution. I putted the connector jar in JBOSSHOME/modules/org/hibernate/main and changed the module.xml...i dont know why that works..but it works!!

The error message you got from Hibernate

Error creating Session: org.hibernate.HibernateException: Specified JDBC Driver com.mysql.jdbc.Driver class not found

occurs because the class com.mysql.jdbc.Driver is missing from your classpath, ie. the jar containing it should be in WEB-INF/lib . Add the mysql connector jar to that folder.

Inside my domain.xml (or standalone.xml) I have this:

<datasource jta="true" jndi-name="java:jboss/Datasource" pool-name="MySqlDS" enabled="true" use-java-context="true" use-ccm="true">
    <connection-url>jdbc:mysql://localhost:3306/DBName</connection-url>
    <driver>com.mysql</driver>
    <security>
        <user-name>name</user-name>
        <password>pass</password>
    </security>
</datasource>
<drivers>
    <driver name="com.mysql"module="com.mysql">
    <xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
    </driver>
</drivers>

inside the tag:

<subsystem xmlns="urn:jboss:domain:datasources:1.1">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM