-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: problem with dialect.
PostPosted: Sun Mar 19, 2006 2:56 pm 
Newbie

Joined: Sat Mar 18, 2006 10:31 am
Posts: 3
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.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 19, 2006 4:27 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
See the docs http://www.hibernate.org/hib_docs/annotations/reference/en/html/ch01.html#setup-configuration
for sample xml configuration.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.