The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

macinsmith (3) [Avatar] Offline
#1
I'm running Hibernate 3.1 on Mac OS X, with MySQL 4.0.20 under Eclipse 3.1.1.

I'm trying to run the Hello World example in chapter 2. I created the Message class, the Message.hbm.xml file and a hibernate.properties file and I kept getting the error "Hibernate Dialect must be explicitly set". So I copied all of the configuration information that I had put in the properties file and made calls to the Configuration.setProperties class and things worked. I turned on JUnit and found that it reported at INFO Environment:494 it found and read the properties file, so I don't understand why it isn't working. My properties file is shown below:
---
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.connection.driver_class=com.mysql.jdbc.Driver
hibernate.connection.url=jdbc:mysql:///helloworld
hibernate.connection.username=hiberuser
hibernate.connection.password=secret

hibernate.c3p0.min_size=5
hibernate.c3p0.max_size=20
hibernate.c3p0.timeout=300
hibernate.c3p0.max_statements=30
hibernate.c3p0.idle_test_period=3001
---
I'm launching this under a JUnit test.
macinsmith (3) [Avatar] Offline
#2
Re: configuring with hibernate.cfg.xml-- problem solved
Problem solved. I forgot to put the following call in the code.

cfg.configure();

Once I did, things started working.
jayhawk (2) [Avatar] Offline
#3
Re: configuring with hibernate.cfg.xml-- problem solved
I'm having the same problem, but I'm using the HelloWorld JPA application. In JPA you don't call cfg.confg(). You simply reference a Persistence Unit. Here's my persistence.xml file, which seems correct to me.

[pre]<persistence xmlns="http://java.sun.com/xml/ns/persistence" >
xmlnssmiliesi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
<persistence-unit name="helloworld">
<!-- <br /> The provider only needs to be set if you use several JPA providers <br /> <provider>org.hibernate.ejb.HibernatePersistence</provider> <br /> -->

<!-- This is required to be spec compliant, Hibernate however supports auto-detection even in JSE. -->
<class>hello.Message</class>

<properties>
<!-- Scan for annotated classes and Hibernate mapping XML files -->
<property name="hibernate.archive.autodetection" value="class, hbm"/>

<!-- SQL stdout logging <br /> <property name="hibernate.show_sql" value="true"/> <br /> <property name="hibernate.format_sql" value="true"/> <br /> <property name="use_sql_comments" value="true"/> <br /> -->

<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.url" value="jdbc:mysql://localhost/hellojpa"/>
<property name="hibernate.connection.username" value="rods"/>
<property name="hibernate.connection.password" value="rods"/>

<property name="hibernate.c3p0.min_size" value="5"/>
<property name="hibernate.c3p0.max_size" value="20"/>
<property name="hibernate.c3p0.timeout" value="300"/>
<property name="hibernate.c3p0.max_statements" value="50"/>
<property name="hibernate.c3p0.idle_test_period" value="3000"/>

</properties>
</persistence-unit>

</persistence>[/pre]

As you can see, I'm definitely setting the dialect. I simply replaced the HSQL dialect with a MySQL one. What's wrong with this?
jayhawk (2) [Avatar] Offline
#4
Re: configuring with hibernate.cfg.xml-- problem solved
My problem has been solved. Here's what was wrong in my setup.

I needed to make sure persistence.xml was in the classpath. It wasn't, so Hibernate never found my dialect property.

This begs the question: Why wasn't an error message given about not finding a persistence.xml file?
sethboopathy (1) [Avatar] Offline
#5
Re: configuring with hibernate.cfg.xml-- problem solved
Did not work for me...

I am using Eclipse 3.3.1.1 with ORACLE 10g as backend database
AnirudhVyas (2) [Avatar] Offline
#6
Re: configuring with hibernate.cfg.xml-- problem solved
Hey Boss Seth,

Did you try hibernate.dialect="Oracl10gDialect" ?

and is Persistence.xml in META-INF folder ?

Regards
Vyas, Anirudh