These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Please help on this issue urgent
PostPosted: Wed Jul 26, 2006 5:38 am 
Newbie

Joined: Wed Jul 26, 2006 5:19 am
Posts: 3
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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 26, 2006 3:36 pm 
Newbie

Joined: Tue Jul 25, 2006 6:39 pm
Posts: 16
Location: Dallas, TX
I would recommend you read this tutorial and it should get you started.

http://www.hibernate.org/hib_docs/v3/re ... orial.html

It does sound like you've copied all of your files into your JDK directory which would be a bad idea.

You should have some kind of development directory and then a project directory under that.

Code:
dev
     + MyProject
               + src
               + bin
                 


put your .java files in your src directory and the .class files into bin.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.