Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
hibernate-3.1
hibernate-annotations-3.1beta8
Mapping documents:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<!-- a SessionFactory instance listed as /jndi/name -->
<session-factory>
<!-- Configurações do banco de dados -->
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost/test</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">123</property>
<mapping class="Banco"/>
</session-factory>
</hibernate-configuration>
Code between sessionFactory.openSession() and session.close():
import org.hibernate.HibernateException;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.classic.Session;
public class HibernateUtil {
private static final SessionFactory sessionFactory;
static {
try {
AnnotationConfiguration cfg = new AnnotationConfiguration();
// set configuration properties
/**
cfg.setProperty("hibernate.show_sql", "true");
cfg.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
cfg.setProperty("hibernate.connection.driver_class", "com.mysql.jdbc.Driver");
cfg.setProperty("hibernate.connection.url", "jdbc:mysql://localhost:3306/test");
cfg.setProperty("hibernate.connection.username", "root");
cfg.setProperty("hibernate.connection.password", "digo25");
// add persistent classes
cfg.addAnnotatedClass(Pet.class);
*/
AnnotationConfiguration an = new AnnotationConfiguration();
an.addFile("C:\\workspace\\hibernate_demo\\bin\\hibernate.cfg.xml");
sessionFactory = an.buildSessionFactory();
} catch (Throwable ex) {
// Log exception!
throw new ExceptionInInitializerError(ex);
}
}
public static Session getSession()
throws HibernateException {
return sessionFactory.openSession();
}
}
Full stack trace of any exception that occurs:
2006-03-19 15:18:36,498 INFO hibernate.cfg.Environment -> Hibernate 3.1.2
2006-03-19 15:18:41,395 INFO hibernate.cfg.Environment -> hibernate.properties not found
2006-03-19 15:18:41,425 INFO hibernate.cfg.Environment -> using CGLIB reflection optimizer
2006-03-19 15:18:41,435 INFO hibernate.cfg.Environment -> using JDK 1.4 java.sql.Timestamp handling
2006-03-19 15:18:44,550 INFO hibernate.cfg.Configuration -> Reading mappings from file: C:\workspace\hibernate_demo\bin\hibernate.cfg.xml
2006-03-19 15:18:45,611 DEBUG hibernate.util.DTDEntityResolver -> trying to locate
http://hibernate.sourceforge.net/hibern ... on-3.0.dtd in classpath under org/hibernate/
2006-03-19 15:18:45,621 DEBUG hibernate.util.DTDEntityResolver -> found
http://hibernate.sourceforge.net/hibern ... on-3.0.dtd in classpath
2006-03-19 15:18:45,822 DEBUG hibernate.cfg.Configuration -> Preparing to build session factory with filters : {}
2006-03-19 15:18:45,822 DEBUG hibernate.cfg.AnnotationConfiguration -> Execute first pass mapping processing
2006-03-19 15:18:45,822 DEBUG hibernate.cfg.AnnotationConfiguration -> Process hbm files
2006-03-19 15:18:46,012 DEBUG hibernate.cfg.AnnotationConfiguration -> Process annotated classes
2006-03-19 15:18:46,072 DEBUG hibernate.cfg.AnnotationConfiguration -> processing manytoone fk mappings
2006-03-19 15:18:46,072 DEBUG hibernate.cfg.Configuration -> processing extends queue
2006-03-19 15:18:46,072 DEBUG hibernate.cfg.Configuration -> processing collection mappings
2006-03-19 15:18:46,092 DEBUG hibernate.cfg.Configuration -> processing native query and ResultSetMapping mappings
2006-03-19 15:18:46,092 DEBUG hibernate.cfg.Configuration -> processing association property references
2006-03-19 15:18:46,092 DEBUG hibernate.cfg.Configuration -> processing foreign key constraints
2006-03-19 15:18:46,112 WARN hibernate.connection.UserSuppliedConnectionProvider -> No connection properties specified - the user must supply JDBC connections
Exception in thread "main" java.lang.ExceptionInInitializerError
at HibernateUtil.<clinit>(HibernateUtil.java:35)
at HibernateTest.main(HibernateTest.java:11)
Caused by: org.hibernate.HibernateException: Hibernate Dialect must be explicitly set
at org.hibernate.dialect.DialectFactory.determineDialect(DialectFactory.java:57)
at org.hibernate.dialect.DialectFactory.buildDialect(DialectFactory.java:39)
at org.hibernate.cfg.SettingsFactory.determineDialect(SettingsFactory.java:378)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:110)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1881)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1174)
at HibernateUtil.<clinit>(HibernateUtil.java:32)
... 1 more
Name and version of the database you are using:
Mysql5
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
My jars (hibernate3 core, annotation e mysql ) are correctly settings in classpath from eclipse. My hibernate.cfg.xml and log4j.properties are settings in \bin from eclipse.
note:
Using
setProperty("hibernate.show_sql", "true");
setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
setProperty("hibernate.connection.driver_class", "com.mysql.jdbc.Driver");
setProperty("hibernate.connection.url", "jdbc:mysql://localhost:3306/test");
setProperty("hibernate.connection.username", "root");
setProperty("hibernate.connection.password", "digo25");
from AnnotationConfiguration it executes well.
Which the problem?
Thanks.