Home Answers Viewqa Hibernate Problem in running first hibernate program....

 
 


suneel
Problem in running first hibernate program....
6 Answer(s)      3 years and 10 months ago
Posted in : Hibernate

View Answers

July 28, 2009 at 11:47 AM


Hi Friend,

It seems that your class has not been found.There may be problem in your directory structure or your class has not been in the defined package. Check it.Even if the error occurs,send the directory structure of your application.

Thanks

July 28, 2009 at 10:54 PM


Hi friend!I haven't changed the source code given in the zip file.The source code of FirstExample.java is as follows
----------------------------------------------------------------------------

package roseindia.tutorial.hibernate;

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{
// 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 contact = new Contact();
contact.setId(6);
contact.setFirstName("Deepak");
contact.setLastName("Kumar");
contact.setEmail("deepak_38@yahoo.com");
session.save(contact);
System.out.println("Done");
}catch(Exception e){
System.out.println(e.getMessage());
}finally{
// Actual contact insertion will happen at this step
session.flush();
session.close();

}

}
}

---------------------------------------------------------------------------
The module directory structure is as folows...
---------------------------------------------------------------------------
->hibernate(module name)
->lib
->net.roseindia.test
->net.roseindia.tutorial.hibernate
->roseindia.tutorial.hibernate
->Book.java
->Contact.java
->FirstExample.java
......
->Referenced libraries
->ant-1.6.2.jar
->ant-antlr-1.6.2.jar
->ant-junit-1.6.2.jar
->ant-launcher-1.6.2.jar
->ant-swing-1.6.2.jar
->antlr-2.7.4.jar
->c3p0-0.8.5.jar
->cglib-full-2.0.2.jar
->cleanimports.jar
->commons-collections-2.1.1.jar
->commons-logging-1.0.4.jar
->concurrent-1.3.2.jar
->connector.jar
->dom4j-1.5.2.jar
->ehcache-1.1.jar
->hibernate3.jar
->jaas.jar
->jacc-1_0-fr.jar
->jaxen-1.1-beta-4.jar
->jboss-cache.jar
->jboss-common.jar
->jboss-jmx.jar
->jboss-remoting.jar
->jboss-system.jar
->jdbc2_0-stdext.jar
->jgroups-2.2.7.jar
->jta.jar
->junit-3.8.1.jar
->log4j-1.2.9.jar
->mysql-connector-java-3.0.16-ga-bin.jar
->mysql-connector-java-3.1.6-bin.jar
->oscache-2.1.jar
->proxool-0.8.3.jar
->swarmcache-1.0rc2.jar
->versioncheck.jar
->xerces-2.6.2.jar
->xml-apis.jar
->JRE system libraries[JRE1.6.0_01]
->contact.hbm.xml
->hibernate.cfg.xml
--------------------------------------------------------------------------
Can u figure out where did i go wrong?Thanks in advance..!

July 29, 2009 at 5:47 PM


Hi Friend,

Try the following code:'FirstExample.java'

package roseindia.tutorial.hibernate;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

public class FirstExample {
public static void main(String[] args) {
Session session = null;
Transaction tx=null;
try{

// 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 contact = new Contact();
contact.setFirstName("anusmita");
contact.setLastName("singh");
contact.setEmail("anu@yahoo.com");
contact.setId(3);
tx = session.beginTransaction();
session.save(contact);
tx.commit();
System.out.println("Done");
System.exit(0);
}catch(Exception e){
System.out.println(e.getMessage());
}finally{

session.flush();
session.close();

}

}
}

Thanks

July 31, 2009 at 2:20 AM


I have changed to galileo and used your code.It just worked fine.Thanks man..!But I got a message as below.What does that mean?Is it a harmful message?
-----------------------------------------------------------------------

Hibernate: insert into CONTACT (FIRSTNAME, LASTNAME, EMAIL, ID) values (?, ?, ?, ?)

------------------------------------------------------------------------
Thanks,I am a complete newbie to hibernate.It may be a petty thing to ask...

January 7, 2011 at 7:33 PM


First thing you need to check is that your eclipse version should have the necessary hibernate plugins, switching to galileo might have worked because it might had the necessary hibernate plugins, also secondly you should check the hibernate.cfg.xml file, in that file the user should be set to "root" and the password should be set to your current mysql "password", remember that their is hibernate.cfg.xml in bin folder also, also check if you have installed proper JDBC for mysql database. --Alok Dethe


July 22, 2011 at 3:06 AM


Hibernate: insert into CONTACT (FIRSTNAME, LASTNAME, EMAIL, ID) values (?, ?, ?, ?). dont get confusion internally hibernate generated hql query for inserting data dynamically. mean like preparedstatement we pass our user input for every Questionmark.same like that dynamically,runtime,user entered input inserted in the place of '?" mean dynamic what u enter that will insert whether input coming from webpage or hotcode mean user passed in main method instead of webpage.









Related Pages:
Problem in running first hibernate program.... - Hibernate
Problem in running first hibernate program....  Hi...I am using... programs.It worked fine.To run a hibernate sample program,I followed the tutorial below and installed the hibernate tools succuccfully. http://www.roseindia.net
Running First Hibernate 3.0 Example
Running First Hibernate 3.0 Example   .... This will run the Hibernate example program in Eclipse following output... first Hibernate 3.0 example
Running First Hibernate 3.0 Example
Running First Hibernate 3.0 Example   ... first project very easily. In this example we are connecting our program.... In this section I showed you how to run the our first Hibernate 3.0 example
hibernate problem
:12) i am getting this prob while running my hibernate program in Eclips please...hibernate problem  please help me.... log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment). log4j:WARN Please
Running problem with NoughtsAndCrossesGame in blank
Running problem with NoughtsAndCrossesGame in blank  Hi i was having problem created NoughtsAndCrossesGame in end the it works but i runs the gui...) then it is "X" // shot as "X" player always goes first
Java Compilation error. Hibernate code problem. Struts first example - Hibernate
Java Compilation error. Hibernate code problem. Struts first example  Java Compilation error. Hibernate code problem. Struts first example
hibernate
hibernate   i am using hibernate3.2.5 and oracle9i. First i set classpath to ojdbc14.jar and all the hibernate jar files to path env variable.After that when i try to execute the program i got an error "unknown oracle major
Hibernate code problem - Hibernate
Hibernate code problem  how to write hibernate Left outer join program
Hibernate code problem - Hibernate
Hibernate code problem  Hi This is Raju.I tried the first example of Hibernate material what u have given. I have written contact.java... session.flush(); i am using hibernate 3.3.1 and I kept hibernate3.jar
Hibernate code problem - Hibernate
Hibernate code problem   Hi This is Raju I tried the first example of hibernate course material.This is to insert a record into CONTACT table.Is Hibernate code automatically creates the CONTACT table and then insert
Depth-first Polymorphism - tutorial
Depth-first Polymorphism 2001-02-15 The Java Specialists' Newsletter [Issue 009] - Depth-first Polymorphism Author: Dr. Heinz M. Kabutz If you...: Greenspun's Tenth Rule of Programming:"any sufficiently complicated C or Fortran program
Writing First Hibernate Code
Writing First Hibernate Code     ... table. Writing First Persistence Class Hibernate uses the Plain Old Java Objects... running on localhost. Developing Code to Test Hibernate example Now we are ready
First Program
Now, lets move ahead for printing the first and most simple & common example of programming “Hello World”. <html> <body> <... like PHP file. After compiling, testing and running the programme, save
First Java Program
First Java Program       In this section you will learn how to develop your first Java program and then compile and test the same on your development machine. Write first Program
problem running a servlet on tomcat.
problem running a servlet on tomcat.  i have followed the steps given... suppose that should mean that my tomcat server is up and running. but whn i try... be the problem? please help me out
Compiling and Running Java program from command line
Compiling and Running Java program from command line - Video tutorial... of compiling and running java program from command line. We have also video... the process of compiling and running the Java program from command prompt
Running and deploying Tomcat Server
Running and deploying Tomcat Server  HI Somebody has given the solution but it doesn't work out. kindly tell the solution for my problem which i described below I want to run a simple program on servlet and the application
About running the Tomcat Server
About running the Tomcat Server   HI I want to run a simple program on servlet and the application is a simple program Hello world... and lib and web.xml folders. Now i compiled Helloworld program in myapps
Problem with open connection - Hibernate
Problem with open connection  Hi Team, I am running one hibernate application and the database is ORACLE 10g.I am getting the below error.I connected to the database by using JDBC(with same driver and url).Please tell me
First Hibernate 4 Example with Eclipse
First Hibernate 4 Example with Eclipse In this tutorial you will learn that how easily you can do your first example of Hibernate 4 with Eclipse First of all to do an example of Hibernate 4 you should have installed an appropriate
About running the Applet Program
About running the Applet Program  Hi I have composed an Applet Program and compiled the program, until that it is fine but how to run the Applet program(compiling i typed as javac AppletDemo.java)? Is compiling
About running the Applet Program
About running the Applet Program  Hi I have composed an Applet Program and compiled the program, until that it is fine but how to run the Applet program(compiling i typed as javac AppletDemo.java)? Is compiling
Running core java program
Running core java program  I am jayesh raval. I am going to make simplae program and at the time of runnint that program I found class not found exception. I have clear source of that program and that is right in the syntax. so
Struts first example - Struts
Struts first example  when i am doing struts first example , it is raising 404 error sometimes it is raised 500 error. what is the problem, and how to do the first program in struts. please give reply with regad's
program is not running in Eclipse.... - WebSevices
program is not running in Eclipse....  Hi i following the tutorial for eclips in roseindia. I am able to creat the simple java application but when i am clicking windows->show view->console then i am getting the console
hibernate configuration with eclipse 3.1 - Hibernate
project.its not running. so i want to about the whole process. i have simple hibernate program code and with struts also. so please tell me the step...hibernate configuration with eclipse 3.1  Dear Sir, i got your mail
Hello world (First java program)
and running. Hello world program is the first step of java programming  language... Hello world (First java program)   ... to develop the robust application. Java application program is platform
process of compiling and running java program
process of compiling and running java program  Explain the process of compiling and running java program. Also Explain type casting
Create First Program
Create First Program     ... program. For developing a java program you just need  a simple text editor like "notepad".  Open the notepad and write your program
spring first example - Spring
spring first example  I am trying my first example of spring from... environments was not found on the java.library.path: C:\Program Files\Apache...:\WINDOWS;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files
java and xml problem. plz see this 1 first - XML
java and xml problem. plz see this 1 first  hi, i need to write a java program that generates an xml file as follows: xxx... ]]> s i have witten a program in java
fIRST APPLICATION - Hibernate
fIRST APPLICATION  Dear Sir, with due respect,it is here to tell you i am beginner in hibernate.AS I M TRYING TO RUN YOUR FIRST APPLICATION OF HIBERNATE. BUT IT IS SHOWING exception Exception in thread "main   Hi friend
Java Compilation and running error - RMI
showing problem. Please tell me why I am unable to run this program with Java...Java Compilation and running error   The following set of programs... some problem and gives following on compilation"java uses unchecked or unsafe
hibernate - Hibernate
hibernate  Hai,This is jagadhish I have a problem while developing insert application of Hibernate.The application is compiled,while running..., As per your problem exception is related to ant.Plz check the lib for Ant
J2EE Tutorial - Running RMI Example
;/html>   How to compile and run the RMI-IIOP program? 1) We require jndi package for running this program.  ... J2EE Tutorial - Running RMI Example    
My first Java Program
My first Java Program  I have been caught with a practical exam to do the following: Write a program that takes input from a user through the command line. The user must be prompt to enter a sentence (anything). The sentence
Hibernate - Hibernate
Hibernate  Hai this is jagadhish while running a Hibernate...:11 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute INFO: Running hbm2ddl.../hibernate/ Please specify your requirements in detail. It would be good
Hibernate code problem - Hibernate
Hibernate code problem  Hi, This is Birendra Pradhan.I want... & Regards Birendra  Hi friend, For solving the problem visit to : http://www.roseindia.net/hibernate/index.shtml Thanks
error while running the applet - Java Beginners
is correct but u have problem in running the program. You follow the following steps...); ++num; } } } } i have problem while running the code , error...error while running the applet  import java.applet.Applet; import
hibernate code problem - Hibernate
hibernate code problem  suppose i want to fetch a row from the table... . Please visit for more information. http://www.roseindia.net/hibernate/selectclause.shtml If you have any problem this send me detail and source code
Hibernate - Hibernate
Hibernate  Hai this is jagadhish, while executing a program in Hibernate in Tomcat i got an error like this HTTP Status 500.... Hopefully this will solve your problem. Regards Deepak Kumar
How to create first program in Java?
How to create first program in Java?  Hi, I am new in Java programming. Tell me How to create first program in Java? Thanks   Hi, Read more at First Java Program. Thanks
Hello world (First java program)
Hello world (First java program)   .... Hello world program is the first step of java programming  language... Compiling and Running the program Now open the command prompt to compile
hibernate code problem - Hibernate
hibernate code problem  String SQL_QUERY =" from Insurance...: " + insurance. getInsuranceName()); } in the above code,the hibernate...= request.getParameter("name"); For more information on hibernate visit to : http
hibernate insertion problem - Hibernate
hibernate insertion problem  Hi , Thanks for the material .Its very gud . when i run FirstExample.java i get the message insertion has been done int the table contact . but whne i look into database data is not inserted
My first struts 2 program
from one page to another. Details: I am trying my first Struts 2 example program. I want to pass values from first loginpage.jsp to displaypage.jsp. I...My first struts 2 program  Hi, Please help me for my first struts 2
Hibernate code problem - Hibernate
Hibernate code problem  Hai, iam working on simple login application using hibernate in spring. I've used Spring dependency injection too.I struck at DAO(data access Object)layer while executing the select statement in HQL
Hibernate code - Hibernate
Hibernate code   I am facing a problem in hibernate program. Error is ::: Error in reading contact.hbm.xml contact.hbm.xml is my hibernate mapping file.  Hi Friend, check whether you have specified correct path
Hibernate error - Hibernate
Hibernate error  I hava following error while running hibernate.../tutorial/hibernate. But I have following error. log4j:WARN No appenders...(FirstExample.java:35) /hibernate.cfg.xml not found Please solve this problem

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.