Hi all ,
This is Balaji. I am new to hibernate concept.i would like to have help .i have just started to write a hibernate program.for me its showing error. this one i got it from roseindia and i tried in my local system .need help as soon as possible
its my hibernate.cfg.xml
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost/test</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password"></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>
<!-- Mapping files -->
<mapping resource="contact.hbm.xml"/>
</session-factory>
</hibernate-configuration>
contact.hbm.xml
<hibernate-mapping>
<class name="Contact" table="CONTACT">
<id name="id" type="long" column="ID" >
<generator class="assigned"/>
</id>
<property name="firstName">
<column name="FIRSTNAME" />
</property>
<property name="lastName">
<column name="LASTNAME"/>
</property>
<property name="email">
<column name="EMAIL"/>
</property>
</class>
</hibernate-mapping>
Firstexample.java
package ram;
import java.util.*;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
/**
* @author Deepak Kumar
*
*
http://www.roseindia.net
* Hibernate example to inset data into Contact table
*/
public class FirstExample {
public static void main(String[] args) {
Session session = null;
try{
System.out.println(" Record");
// This step will read hibernate.cfg.xml and prepare hibernate for use
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
System.out.println(" afterRecord");
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 contact = new Contact();
contact.setId(2);
contact.setFirstName("Deepak");
contact.setLastName("Kumar");
contact.setEmail("deepak@yahoo.com");
session.save(contact);
System.out.println(" Record");
}catch(Exception e){
System.out.println(e.getMessage());
}finally{
// Actual contact insertion will happen at this step
session.flush();
session.close();
}
}
this All the files i put in under bin in j2sdk along with pojo class Contact.java.when i am compiling contact.java its compiling.when i compile firstexample.java its compile but during runtime it showing error
Exception in thread "main" java.lang.NoClassDefFoundError: FirstExample
i have set the classpath for both hibernate.jar and mysql connector .jar file
i dont know where its wrong .can u pls anyone help .i am in this issue for
past two days.if any one help i can proceed for further concepts in hibernate.the control is not entering into hibernate.cfg.xml.please help me on this issue
waiting for u r reply