• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

First Test App Not Working

 
Mike London
Ranch Hand
Posts: 1216
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My first implementation of Hibernate seems to be failing right away on the following line of code:

SessionFactory factory = new Configuration().buildSessionFactory();

The error is:

org.hibernate.HibernateException: Hibernate Dialect must be explicitly set

But, in my hibernate configuration file, I have...

<property name="dialect">org.hibernate.dialect.MySQLDialect</property>

The hibernate configuration file is in the same directory as the other classes generated. I've tried to move it to the root of the Web app and other places, but I keep getting the same error.

I've tested the DB Connection so that part is OK.

Can anyone tell me what I'm doing wrong?

Thanks very much in advance.

Mike
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a quick little tutorial that will show you how to validate your environment and make sure everything is working:

How to Validate a MySQL, Hibernate and JPA Configuration in a Windows Environment

Here's also a URL to show you how my environment was set up:

YouTube Video on Setting up a MySQL/Hibernate/Java Environment on Windows XP

My guess is that the hibernate.cfg.xml file simply isn't being picked up, which I think you've already figured out.

Which environment are you using?

In the tutorial I referenced, I have a folder named C:\_mycode

In that folder, I have a class named com.examscam.model.User

C:\_mycode\com\examscam\model\User.class

I then put the hibernate.cfg.xml file in the C:\_mycode folder.

Using just the JDK, I ran a SchemaExport to create the database with the following command (All on one line):

C:\_mycode>c:\_jdk1.6\bin\java -classpath "C:\_hiblib\*";C:\_mycode com.examscam.model.User

With the -classpath reference to the C:\_mycode folder, the JDK picks up the configuration file, and everything runs.

By the way, make sure the configuration file is where the compiled code gets placed, not the source code. So, if you're using a web app, you probably want to see the hibernate configuration file in the WEB-INF\classes directory.

By the way, what's the name of your configuration file. Make sure you haven't simply named it incorrectly, using a dash instead of a period, or transposed letters to spell xlm instead of xml, or cgf instead of cfg.

Good luck!

-Cameron McKenzie
 
Mike London
Ranch Hand
Posts: 1216
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply.

I used MyEclipse which automates most of the steps including the naming of the configuration file.

Hmmmm....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic