This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate Dialect must be explicitly set

 
Niklas Johansson
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Using
Hibernate 3.3.1 GA
Hibernate Annotations 3.4.0 GA
JEE 5
JSE 1.6
Eclipse 3.4.1
MySQL 5.0

I am trying to learn Hibernate using annotations. I have managed to get it working not using annotations but when I am converting to annotations things does not work that smooth anymore.

I have tried putting the connection properties in both hibernate.properties XOR hibernate.cfg.xml with no improvements. I found this link wich can be a hint (that can help someone wiser than me...): http://wyding.blogspot.com/2009/03/why-you-got-hibernate-dialect-must-be.html And yes, I am using Eclipse Ganymede.

hibernate.properties:




hibernate.cfg.xml



In my HibernateUtil class i changed
sessionFactory=new Configuration().configure().buildSessionFactory()
to
sessionFactory = new AnnotationConfiguration().buildSessionFactory()
I have seen in some instructions that
sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory()
is used instead, but then I get the error:
/hibernate.cfg.xml not found
instead.

When searching for this problem there are a lot of people having the same problem but I cannot find any answers... And if there are any answers on hibernates own forum it's impossible to find out now since the site has been unavailable for a few days already...

Any help would be most apreciated, about to get a bit (just a little...eh) frustrated.

Thank you in advance!

Regards,
Niklas
 
Niklas Johansson
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found the solution:

The suggestion to change

sessionFactory=new Configuration().configure().buildSessionFactory()


to

sessionFactory = new AnnotationConfiguration().buildSessionFactory()


does not work but either of following works:

sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory()


or

AnnotationConfiguration scfg = new AnnotationConfiguration();
scfg.configure();
sessionFactory=scfg.buildSessionFactory();


Also, I had some other errors along the road which made me think that either of the two working solutions wasn't working, but they did at the end.

Hope this can help someone else with the same problem!

Regards,
Niklas
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also this isn't the forum for Hibernate questions. Our Object Relation Mapping forum is where you put Hibernate questions.

So I am going to move this to that forum

Thanks

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic