Try this it'll definitely work
Code:
package com.genuitec.hibernate;
import net.sf.hibernate.*;
public class HibernateTest {
public static void main(String[] args) {
// Step 1 - Create a new entity
EchoMessage message = new EchoMessage();
// Step 2 - Set message field
message.setMsg("Hello Hibernate, from MyEclipse!");
try {
// Step 3 - Get a Hibernate Session
Session session = SessionManager.currentSession();
// Step 4 - Persist entity to database
Transaction tx = session.beginTransaction();
session.save(message);
tx.commit();
System.out.println("Save successful.");
} catch (HibernateException e) {
System.out.println("Save failed.");
} finally {
try {
// Step 5 - close the session
SessionManager.closeSession();
} catch (HibernateException e1) {
// do nothing
}
}
}
}