-->
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.  [ 5 posts ] 
Author Message
 Post subject: What is wrong with my code generation code snippet?
PostPosted: Sun Dec 03, 2006 6:53 am 
Newbie

Joined: Fri Nov 17, 2006 7:24 pm
Posts: 16
Hi
Thank you for reading my post.
can some one please help me with this problem?
I am trying to generate database schema using hibernate schema export features.
I should say that i have annotated java classes which i want to generate schema from them.


Hibernate version: 3.2

Mapping documents:

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>



Code that i used to generate schema.


Code:

package learn_hiber.chapter4;

import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.tool.hbm2ddl.SchemaExport;

public class GenerateSchema
{

    public static void main(String[] args)
    {
       // Amended to allow a path (to the hibernate.cfg.xml) to
       // be passed to the configuration.
        AnnotationConfiguration cfg = ExampleConfiguration.getConfig();;
        SchemaExport schemaExport = new SchemaExport(cfg);
        schemaExport.create(true, true);
    }
}




[exception that i get]

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:18)
Java Result: 1





Example configuration that i used

Code:

package learn_hiber.chapter4;

import org.hibernate.cfg.AnnotationConfiguration;

public class ExampleConfiguration
{
    public static AnnotationConfiguration getConfig() {
       AnnotationConfiguration cfg = new AnnotationConfiguration();
        cfg.addAnnotatedClass(Author.class);
        cfg.addAnnotatedClass(Book.class);
        cfg.addAnnotatedClass(ComputerBook.class);
        cfg.addAnnotatedClass(Publisher.class);
        return cfg;
    }
}





can some one please tell me what i am doing wrong?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 03, 2006 8:22 am 
Senior
Senior

Joined: Tue Aug 23, 2005 8:52 am
Posts: 181
ExampleConfiguration.getConfig() does not read from the hibernate.cfg.xml where you have the dialect defined. Use something like AnnotationConfiguration.addXML(String) or AnnotationConfiguration.addResource() to load the hibernate.cfg.xml which has all the other properties defined.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 03, 2006 9:04 am 
Newbie

Joined: Fri Nov 17, 2006 7:24 pm
Posts: 16
Hi
Thank you for reply.
i changed the ExampleConfiguration as follow but i still get the same error message.

Code:

package learn_hiber.chapter4;

import org.hibernate.cfg.AnnotationConfiguration;

public class ExampleConfiguration
{
    public static AnnotationConfiguration getConfig() {
       AnnotationConfiguration cfg = new AnnotationConfiguration();
     cfg.addResource("learn_hiber/hibernate.cfg.xml");
             return cfg;
    }
}



I should say that learn_hiber is the root package and chapter4 is a package inside it.
i mean i have src/learn_hiber/chapter4 which the hibernate.cfg.xml is located in learn_hiber folder.

thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 03, 2006 6:10 pm 
Newbie

Joined: Sat Dec 02, 2006 10:55 pm
Posts: 10
Are you sure the hibernate.cfg.xml file is in the right directory


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 04, 2006 5:20 am 
Newbie

Joined: Fri Nov 17, 2006 7:24 pm
Posts: 16
Thank you all for your reply.
I solve the problem by loading hibernate.cfg.xml in the configure method.
now it works fine.

thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.