rhlpnt wrote:
My code is running fine...everything is o.k. But when i check my database .it reflects empty set...my code is written below
[java] log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
     [java] log4j:WARN Please initialize the log4j system properly.
     [java] Inserting Record
     [java] Done
     [java] Hibernate: insert into CONTACT (FIRSTNAME, LASTNAME, EMAIL, ID) values (?, ?, ?, ?)
BUILD SUCCESSFUL
package hibernate;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class FirstExample {
	
	private Session session;
	public static void main(String[] args) {
	    Session session = null;
	    try{
	    	Configuration configuration = new Configuration();
	        configuration.setProperty("hibernate.connection.driver_class",  com.mysql.jdbc.Driver.class.getName());
	        configuration.setProperty("hibernate.connection.url",("jdbc:mysql://localhost:3306/hibernatetutorial"));
	        configuration.setProperty("hibernate.connection.username", "root");
	        configuration.setProperty("hibernate.connection.password", "test");
	        configuration.setProperty("hibernate.connection.pool_size", "1");
	        configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
	        configuration.addClass(Contact.class);
	        session = configuration.buildSessionFactory().openSession();
	    	
	    	//"C:\\svn\\workspace\\hibernateTutorial\\cfg\\hibernate.cfg.xml"
	      // This step will read hibernate.cfg.xml and prepare hibernate for use
	      SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
	       session =sessionFactory.openSession();
	        //Create new instance of Contact and set values in it by reading them from form object
	         System.out.println("Inserting Record");
	        Contact c = new Contact();
	        c.setId(3);
	        c.setFirstName("Deepak");
	        c.setLastName("Kumar");
	        c.setEmail("deepak_38@yahoo.com");
	        session.persist(c);
	        System.out.println("Done");
	    }catch(Exception e){
	    	e.printStackTrace();
	      System.out.println(e.getMessage());
	    }finally{
	      // Actual contact insertion will happen at this step
	      session.flush();
	      session.close();
	      }
	    
	  }
}