I am using Hibernate 3 and MySQL5.5.
I am a newbie to hibernate and I am getting the below Exception
Exception in thread "main" org.hibernate.HibernateException: 'hibernate.dialect' must be set when no Connection available
at org.hibernate.dialect.resolver.DialectFactory.buildDialect(DialectFactory.java:106)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:152)
I have set the Dialect property in hibernate.cfg.xml file. I tried a lot of combinations
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
<property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>
<property name="DIALECT">org.hibernate.dialect.MySQL5Dialect</property>
What is the actual property name ? Hibernate.dialect or only dialect ? What can be possible property values ?
I am adding some more information, I used
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
as suggested by below answers.
I am not even building any code just trying to create simple configuration:
Configuration cfg = new Configuration().addClass(Employee.class);
sessionFactory = cfg.buildSessionFactory();
Below is the actual Configuration file
<?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.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.url">jdbc:mysql://localhost/test</property>
<property name="connection.username">root</property>
<property name="connection.password">root1234</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="hbm2ddl.auto">create</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<property name="current_session_context_class">thread</property>
<!-- Mapping files will go here.... -->
</session-factory>
</hibernate-configuration>
I suspect the hibernate.cfg.xml is not being found ? I have placed it in the same package where the source code for Employee.class is there. Infact moving around this file causes the same error, so it is not actually found :-( Where to keep it ? This is a standalone Test program :-(
org.hibernate.dialect
, you can find a list of possible ones in the relevant javadoc for your version. Also, thehibernate.cfg.xml
should be in your classpath, which could possibly mean a bunch of places, so we're also gonna need to know the build system you're using, i.e., for Maven it would beproj/src/main/resources
configure(File path)
method on yourConfiguraion
object with the full path & see what happens...