Thank you for reading my post
I have problem in SchemaExport class to export schema of some annotated class.
I am trying some code from a book, but it looks to have some problems.
I add all source code that are required here.
Hibernate version: 3.2
Name and version of the database you are using: MySQL 5
hibernate configuration file:
Code:
<?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>
<session-factory>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://127.0.0.1/learnHiberDB</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<mapping package="learn_hiber.chapter4"/>
<mapping class="learn_hiber.chapter4.Author"/>
<mapping class="learn_hiber.chapter4.Book"/>
<mapping class="learn_hiber.chapter4.ComputerBook"/>
<mapping class="learn_hiber.chapter4.Publisher"/>
</session-factory>
</hibernate-configuration>
Full stack trace of any exception that occurs:Code:
Exception in thread "main" org.hibernate.HibernateException: The dialect was not set. Set the property hibernate.dialect.
at org.hibernate.dialect.Dialect.getDialect(Dialect.java:635)
at org.hibernate.dialect.Dialect.getDialect(Dialect.java:657)
at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:84)
at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:59)
at learn_hiber.chapter4.GenerateSchema.main(GenerateSchema.java:25)
Code:
package learn_hiber.chapter4;
import java.io.File;
import java.io.IOException;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.tool.hbm2ddl.SchemaExport;
public class GenerateSchema
{
public String printURL(){
return this.getClass().getResource("/learn_hiber/hibernate.cfg.xml").getPath();
}
public static void main(String[] args)
{
GenerateSchema gn = new GenerateSchema();
// Amended to allow a path (to the hibernate.cfg.xml) to
// be passed to the configuration.
AnnotationConfiguration cfg = ExampleConfiguration.getConfig();;
System.out.println(gn.printURL());
cfg.addFile(new File(gn.printURL()));
SchemaExport schemaExport = new SchemaExport(cfg);
schemaExport.create(true, true);
}
}