• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception in thread "main" java.lang.ExceptionInInitializerError

 
Savannah David
Greenhorn
Posts: 16
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,

I am getting an exception while executing a piece of code. Please help me out.

Here the exception:


Exception in thread "main" java.lang.ExceptionInInitializerError
at com.dao.MessageDAO.addMessage(MessageDAO.java:12)
at Test.main(Test.java:43)
Caused by: org.hibernate.HibernateException: Hibernate Dialect must be explicitly set
at org.hibernate.dialect.DialectFactory.determineDialect(DialectFactory.java:57)
at org.hibernate.dialect.DialectFactory.buildDialect(DialectFactory.java:39)
at org.hibernate.cfg.SettingsFactory.determineDialect(SettingsFactory.java:378)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:110)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1881)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1174)
at com.util.HibernateUtil.<clinit>(HibernateUtil.java:23)
... 2 more

Now i am putting all the 3 classes which i have used in the project:

HibernateUtil.java :

package com.util;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class HibernateUtil {

static SessionFactory sessionFactory;
static
{
sessionFactory=new Configuration().buildSessionFactory();

}
public static SessionFactory getSessionFactory()
{
return sessionFactory;
}

}

MessageDAO.java :

package com.dao;

import org.hibernate.Session;
import org.hibernate.Transaction;
import com.entity.Message;
import com.util.HibernateUtil;

public class MessageDAO {
public void addMessage(Message message)
{
Session session=HibernateUtil.getSessionFactory().openSession();
Transaction transaction=session.getTransaction();
transaction.begin();
session.save(message);
transaction.commit();
session.close();
}

}

Test.java :


import com.dao.MessageDAO;
import com.entity.Message;


public class Test {


public static void main(String[] args) {

Message message=new Message();
message.setMessageId(104);
message.setMessageText("friday morning");
message.setMessageAuthor("mr love");
MessageDAO messageDAO=new MessageDAO();
messageDAO.addMessage(message);


}

}

here,s the mapping:

<?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">org.gjt.mm.mysql.Driver</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost/test</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
<property name="hibernate.show_sql">true</property>
<mapping resource="./com/entity/Message.hbm.xml" />
</session-factory>
</hibernate-configuration>


Thanks in advance..
 
Savannah David
Greenhorn
Posts: 16
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ues sessionFactory=new Configuration().configure().buildSessionFactory(); in HibernateUtil class.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic