Hi,
I am trying to create a small java class and use hibernate..But i'm getting the following error:
Exception in thread "main" 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)
The java class is :
public class TestExample {
private SessionFactory factory;
public void createHoney(Honey honey){
Transaction tx = null;
Session s = factory.openSession();
try{
tx = s.beginTransaction();
s.save(honey);
tx.commit();
s.close();
}catch(HibernateException he){
he.printStackTrace();
if(tx != null && tx.isActive())
tx.rollback();
}
}
public void deleteHoney(Honey honey){
Session s = factory.openSession();
Transaction tx = null;
try{
tx = s.beginTransaction();
s.delete(honey);
tx.commit();
s.close();
}catch(HibernateException he){
he.printStackTrace();
if(tx != null && tx.isActive())
tx.rollback();
}
}
public void listHoney(){
Transaction tx = null;
Session s = factory.openSession();
try{
tx = s.beginTransaction();
List honeys = s.createQuery("select h from Honey as h").list();
for(Iterator it = honeys.iterator(); it.hasNext();){
Honey hon = (Honey) it.next();
System.out.println("Id : " + hon.getId() + "Honey : " + hon.getName() + " Taste : " + hon.getTaste());
}
tx.commit();
s.close();
}catch(HibernateException he){
he.printStackTrace();
if(tx != null && tx.isActive())
tx.rollback();
}
}
public static void main(String[] args) {
TestExample test = new TestExample();
Configuration cfg = new Configuration()
.addClass(Honey.class)
.setProperty(Environment.HBM2DDL_AUTO,"create");
test.factory = cfg.buildSessionFactory();
Honey forestHoney = new Honey();
Honey countryHoney = new Honey();
forestHoney.setName("Forest honey");
forestHoney.setTaste("very sweet");
countryHoney.setName("Country honey");
countryHoney.setTaste("tasty");
test.createHoney(forestHoney);
test.createHoney(countryHoney);
//test.listHoney();
test.deleteHoney(countryHoney);
test.listHoney();
}
/**
*
*/
public TestExample() {
super();
}
}
Can somebody help?
|