Problems Using Hibernate - JDBC Driver Class Not Found: com.mysql.jdbc.Driver

I have a very strange problem when using hibernate to connect to MySQLDB and add data.

This is the error I get:

JDBC Driver class not found: com.mysql.jdbc.Driver

This is what my hibernate.cfg.xml looks like

<!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.url">jdbc:mysql://localhost:3306/fpa-webapp</property> <property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property> <property name="hibernate.connection.username">root</property> <property name="hibernate.connection.password"></property> <property name="hbm2ddl.auto">update</property> <property name="hibernate.show_sql">true</property> <property name="hibernate.format_sql">true</property> </session-factory> </hibernate-configuration> 

I do not understand why I see a 500 error when switching to the application; he says the driver was not found.

HTTP ERROR 500

Problem with access / fpa -webapp /. Cause:

 Exception constructing service 'ValueEncoderSource': Error invoking 

method for constructing the service org.apache.tapestry5.services.TapestryModule.buildValueEncoderSource (Map, InvalidationEventHub) (when TapestryModule.java:2287) (for servicing 'ValueEncoderSource'): calling the error service fee method org.apache.tapestryHiber.hiber. contributeValueEncoderSource (MappedConfiguration, boolean, HibernateSessionSource, Session, TypeCoercer, PropertyAccess, LoggerSource): creating an exception service "HibernateSessionSource": Error while calling the method for constructing service org.apache.tapestryHourceNodeSourceModeule ListerBuberSourceModule ListerHubnodeSourceModuleBuery Library HibernateCoreModule.java:123) (for the "HibernateSessionSource" service): JDBC driver class not found: com.mysql.jdbc.Driver

I am sure the driver is in the class path.

What could it be?

+4
source share
2 answers

Your driver is not in the classpath.

There are two ways to get to classes:

  • Add it to the global lib directory. For Tomcat, this is TOMCAT_HOME/lib .
  • Include him in the war.

It depends on your requirements that you use.

If you intend to use Tomcat to manage the connection pool, you need to add it to TOMCAT_HOME/lib and instead of defining your data source directly in the sleep mode configuration, you will reference it via jndi .

+1
source

The only plausible explanation is that the Driver class is not in CLASSPATH.

Make sure that the mysql-connector-java (or other appropriate) jar is really in the place where it will be loaded. If you are 100% sure that it is, this may help provide additional information about how you know the class is loading so that we can identify other possible causes.

0
source

All Articles