-->
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.  [ 13 posts ] 
Author Message
 Post subject: Doing simple application. Please help me out...
PostPosted: Wed Jun 03, 2009 1:16 am 
Newbie

Joined: Wed Jun 03, 2009 1:03 am
Posts: 5
Location: India
Hi,
I am very new to hibernate and trying my hand at it for the first time...
I am getting "org.hibernate.HibernateException: Hibernate Dialect must be explicitly set" exception.

I am using Eclipse IDE and my hibernate.cfg.xml file is as follows:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//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://localhost:3306/hibernate_db</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="username">root</property>
<property name="password">akshay</property>

<property name="show_sql">true</property>

<mapping resource="Account.hbm.xml"/>
</session-factory>
</hibernate-configuration>



Exception stack trace:

62 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.3.1.GA
109 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
124 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
187 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
374 [main] INFO org.hibernate.cfg.Configuration - Reading mappings from resource: com/wipro/Account.hbm.xml
374 [main] INFO org.hibernate.cfg.Configuration - Reading mappings from resource: com/wipro/Account.hbm.xml
795 [main] INFO org.hibernate.cfg.HbmBinder - Mapping class: com.wipro.Account -> account
966 [main] WARN org.hibernate.connection.UserSuppliedConnectionProvider - No connection properties specified - the user must supply JDBC connections
Exception in thread "main" org.hibernate.HibernateException: Hibernate Dialect must be explicitly set
at org.hibernate.dialect.DialectFactory.determineDialect(DialectFactory.java:80)
at org.hibernate.dialect.DialectFactory.buildDialect(DialectFactory.java:62)
at org.hibernate.cfg.SettingsFactory.determineDialect(SettingsFactory.java:460)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:155)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2101)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1325)
at com.wipro.Main.main(Main.java:46)



Please suggest where the problem is and suggest what I need to do... any JARs missing or anything that is going wrong...!!

Thank you in advance!


Top
 Profile  
 
 Post subject: Re: Doing simple application. Please help me out...
PostPosted: Wed Jun 03, 2009 2:53 am 
Newbie

Joined: Tue Jun 02, 2009 4:51 am
Posts: 2
Location: Iran
salaam,
open your referenced libraries and check open your hibernate jar file and check its dialect package. first check whether its package names are starting with "org" and then look for mysql dialect classes in dialect package. depend on the version of mysql you are using you should use the appropriate mysql dialect. you can test all my sql dialects to see whether they qork or not for you.
if it is not org packages try this dialect string: "net.sf.hibernate.dialect.MySQLDialect" and tell me whether it solves it or not.

regards,
Hooman Peiro Sajajd

_________________
Hooman Peiro Sajjad


Top
 Profile  
 
 Post subject: Re: Doing simple application. Please help me out...
PostPosted: Wed Jun 03, 2009 3:14 am 
Newbie

Joined: Wed Jun 03, 2009 1:03 am
Posts: 5
Location: India
Walekum asalam Hooman bhai.. thanks for the reply!

I am using hibernate3.jar and it has dialect package starting with org. ...
I am using the MySQL version 5.0.

As per your suggestion I also tried using dialect string: "net.sf.hibernate.dialect.MySQLDialect" from hibernate2.jar...

but that too is not working and showing me the same exception message as given above in red colour font.

I also tried using all the remaining dialects for the MySQL from hibernate3.jar but nopes..! Same exception...!!!

Please help me out of this.. i am going nuts !!!


Top
 Profile  
 
 Post subject: Re: Doing simple application. Please help me out...
PostPosted: Wed Jun 03, 2009 3:25 am 
Newbie

Joined: Fri May 29, 2009 2:21 am
Posts: 12
I hope u tried this,

Replce
org.hibernate.dialect.MySQLDialect
with
org.hibernate.dialect.MySQLInnoDBDialect


Top
 Profile  
 
 Post subject: Re: Doing simple application. Please help me out...
PostPosted: Wed Jun 03, 2009 4:35 am 
Newbie

Joined: Wed Jun 03, 2009 1:03 am
Posts: 5
Location: India
No Sidni,
"org.hibernate.dialect.MySQLInnoDBDialect" also does not work....!!!


Top
 Profile  
 
 Post subject: Re: Doing simple application. Please help me out...
PostPosted: Wed Jun 03, 2009 5:50 am 
Beginner
Beginner

Joined: Fri Feb 13, 2009 5:27 am
Posts: 36
Location: India
plz include following jar in classpath ---> mysql-connector-java-5.1.6-bin.jar
and then try it .may it work!!!!!
bye

_________________
parag


Top
 Profile  
 
 Post subject: Re: Doing simple application. Please help me out...
PostPosted: Wed Jun 03, 2009 6:09 am 
Newbie

Joined: Wed Jun 03, 2009 1:03 am
Posts: 5
Location: India
Parag,
Tried your suggestion ... but still the same exception...!! :(


Top
 Profile  
 
 Post subject: Re: Doing simple application. Please help me out...
PostPosted: Thu Jun 04, 2009 2:01 am 
Beginner
Beginner

Joined: Fri Feb 13, 2009 5:27 am
Posts: 36
Location: India
HI Akshay
can u post the full code...then i wil try my best.(also which jar u are included in ur classpth).

_________________
parag


Top
 Profile  
 
 Post subject: Re: Doing simple application. Please help me out...
PostPosted: Thu Jun 04, 2009 2:14 am 
Beginner
Beginner

Joined: Fri Feb 13, 2009 5:27 am
Posts: 36
Location: India
HI akshay,
also try like this,(covert ur code inthis format and then try)


<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/imagedb</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">mysql</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="current_session_context_class">thread</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="show_sql">true</property>






<mapping resource="map/image.hbm.xml" />
</session-factory>
</hibernate-configuration>

_________________
parag


Top
 Profile  
 
 Post subject: Re: Doing simple application. Please help me out...
PostPosted: Thu Jun 04, 2009 2:17 am 
Beginner
Beginner

Joined: Fri Feb 13, 2009 5:27 am
Posts: 36
Location: India
include these jar to ur classpath.

"msbase.jar"
"mssqlserver.jar"
"msutil.jar"
"mysql-connector-java-5.1.6-bin.jar" "antlr-2.7.6.jar"
"asm-all-2.1.jar"
"cglib-2.2_beta1.jar"
"commons-collections.jar"
"commons-logging-api.jar"
"dom4j-1.4.jar"
"hibernate3.jar" "jta-spec1_0_1.jar"

_________________
parag


Top
 Profile  
 
 Post subject: Re: Doing simple application. Please help me out...
PostPosted: Thu Jun 04, 2009 11:34 pm 
Newbie

Joined: Wed Jun 03, 2009 1:03 am
Posts: 5
Location: India
Hi Parag, Thanks for your help. I am posting my entire program for your help. Please try if you can resolve the gotcha...!

JAVA invocation code:

Code:
/

/
package com.wipro;

import org.hibernate.HibernateException;
import org.hibernate.MappingException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;


public class Main {

   /
*@param args*
/
   public static void main(String[] args) {
      // TODO Auto-generated method stub
      Account account = new Account("Akshay");

      Configuration cfg;
      try {
         cfg = new Configuration().addClass(Account.class);

         SessionFactory sessionFactory = cfg.buildSessionFactory();

         Session session = sessionFactory.openSession();

         session.save(account);

         session.flush();

         session.close();

      } catch (MappingException e) {
         e.printStackTrace();
      } catch (HibernateException e) {
         e.printStackTrace();
      }
   }

}


my mapping file (Account.hbm.xml):
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
   <class name="com.wipro.Account" table="account">
      <id name="id" type="int" unsaved-value="null">
         <column name="id" sql-type="int" not-null="true"/>
         <generator class="assigned"/>
      </id>
      
      <property name="name">
         <column name="name"/>   
      </property>
   </class>
</hibernate-mapping>




my Configuration file (hibernate.config.xml):

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
      <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
      <property name="hibernate.connection.url">jdbc:mysql://localhost/hibernatetutorial</property>
      <property name="hibernate.connection.username">root</property>
      <property name="hibernate.connection.password">akshay</property>
      <property name="hibernate.connection.pool_size">10</property>
      <property name="show_sql">true</property>
      <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
      <property name="hibernate.hbm2ddl.auto">update</property>
     
     <property name="show_sql">true</property>
     
     <mapping resource="Account.hbm.xml"/>
  </session-factory>
</hibernate-configuration>


my JavaBean (Account.java):.
Code:
/**
*
*/
package com.wipro;

import java.io.Serializable;

/**
* @author admin
*
*/
public class Account implements Serializable {

   /**
    *
    */
   private static final long serialVersionUID = 2936147874996596000L;
   
   private int id;
   private String name;
   
   /**
    *
    */
   public Account() {
      
   }   
   public Account(String name, int id) {
      this.name = name;
      this.id = id;
   }
   
   /**
    * @return the id
    */
   public int getId() {
      return id;
   }
   /**
    * @param id the id to set
    */
   public void setId(int id) {
      this.id = id;
   }
   /**
    * @return the name
    */
   public String getName() {
      return name;
   }
   /**
    * @param name the name to set
    */
   public void setName(String name) {
      this.name = name;
   }

}


my Table(account) description from MySQL:
Code:
mysql> use hibernate_db;
Database changed
mysql> desc account;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id       | int(11)       | NO   | PRI | NULL    |       |
| name  | varchar(10) | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.16 sec)

mysql>



Top
 Profile  
 
 Post subject: Re: Doing simple application. Please help me out...
PostPosted: Tue Jun 09, 2009 3:35 am 
Beginner
Beginner

Joined: Fri Feb 13, 2009 5:27 am
Posts: 36
Location: India
HI akshay...ur problm solved!!!!!!!!!!!!!!


just change ur Main.java file (no change in hibernate configuration file )
and plz rate me yar...(i m jocking)


Main.java

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;


public class Main {


public static void main(String[] args) {
// TODO Auto-generated method stub



Session session = null;
try {
Configuration cfg = new Configuration();
Configuration c = cfg.configure();
SessionFactory sf = c.buildSessionFactory();
session = sf.openSession();
Transaction tx = session.beginTransaction();

Account account = new Account("Akshay",1);

session.save(account);
tx.commit();
session.close();



} catch (HibernateException e) {
e.printStackTrace();
}
}

}



ok bye tc ..milte hai ......

_________________
parag


Top
 Profile  
 
 Post subject: Re: Doing simple application. Please help me out...
PostPosted: Tue Jun 09, 2009 4:21 am 
Beginner
Beginner

Joined: Fri Feb 13, 2009 5:27 am
Posts: 36
Location: India
always use Transaction .ok bye.

_________________
parag


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