Problem in running first hibernate program....

Problem in running first hibernate program....

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("[email protected]");
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("[email protected]");
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 Tutorials/Questions & Answers:
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
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
Advertisements
Running First Hibernate 3.0 Example
Running First Hibernate 3.0 Example       Hibernate is free open source software it can..._TO_REPLACE_4 In this section I showed you how to run the our first Hibernate
Running First Hibernate 3.0 Example
Running First Hibernate 3.0 Example   ... first project very easily. In this example we are connecting our program... the Hibernate example program in Eclipse following output will displayed
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
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
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
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
C++ program not running
C++ program not running  Hi, this program need to ask 10 random questions with a random month name. Example: RUN How many days are there in the month of March? 28 No March has 31 days. How many days are there in the month
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
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
Hibernate ORM - learn to create first application
Hibernate ORM - learn to create first application Hibernate ORM 4.2.2.1... in the video. Here we will learn how to create the first application using the Maven dependencies Hibernate 4.2.2.1 was released on 3rd October 2015.In
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
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 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
Hibernate code problem - Hibernate
Hibernate code problem  how to write hibernate Left outer join program
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 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
How to create first Java Program?
How to create first Java Program?  Hi, I am beginner and I want to write first Java program. How I can setup my machine and write first Java program... on creating First Java Program Thanks   HI, Here are the steps to write
Hibernate Example Step by Step in Eclipse
inserted In this section you have created first program in Hibernate which inserts... you step-by-step tutorial of creating first example in Hibernate 4.2. We have... to create the example program Follow the following easy steps and create you hibernate
problem in servlet program
problem in servlet program  Dear Sir, I have a problem to insert the Blob type data like as video file, audio file in the database using Servlet and html code
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
ModuleNotFoundError: No module named 'first_program'
ModuleNotFoundError: No module named 'first_program'  Hi, My... 'first_program' How to remove the ModuleNotFoundError: No module named 'first_program' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'first_program'
ModuleNotFoundError: No module named 'first_program'  Hi, My... 'first_program' How to remove the ModuleNotFoundError: No module named 'first_program' error? Thanks   Hi, In your python
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
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
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
Java program problem
Java program problem  Hi, I took the chance to login here in your.... Please help me. I provided below the program assignment. Thanks in advance. Create program that: Will search through two directory structures and produce
program problem - Java Beginners
program problem  Design and write a Java application that takes as input a single letter and displays the corresponding digit on the telephone. The letters and digits on a telephone are grouped this way: 2 = ABC 4 = GHI 6
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
Problem with Hibernate or 11g
Problem with Hibernate or 11g  Hi I am using Hibernate and 11g in my project. The problem I am facing is I am executing a query from java class... on Created date column by using hibernate query language. The Problem is every
What should I learn first Spring or Hibernate?
What should I learn first Spring or Hibernate?  Hi, What should I learn first Spring or Hibernate? I learned Java and JDBC. I also have project experience in JSP/Servlet. I used tomcat for running my application. Thanks
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... to explain you the process of compiling and running the Java program from command
First Java Program Example
First Java Program Example In this section we will discuss about the first java program example. To create a Java program we would be required to create... how to write your first program in Java. In this example I have created
Problem in updating query in Hibernate - Hibernate
Problem in updating query in Hibernate  Hi, I have used a query to update the existing columns of one table. The query updates the records..., Please visit the following link: http://www.roseindia.net/hibernate
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
First Java Program
your first Java program. In Java, all source code is written in plain text file... Machine. You can write a Hello World program as your first Java program. To write the Hello world program you need simple text editor like note pad and make
Why is my program running an infinite loop? Parallel Arrays Program
Why is my program running an infinite loop? Parallel Arrays Program  Calculate and print the average (this works) Search for Joel in the list, print his data----for some reason this is outputting the wrong data and is outputting
delete query problem - Hibernate
correctly , the problem is only delete query. 2) query.executeUpate(); ->...(); Read for more information. http://www.roseindia.net/hibernate Thanks
servlet program problem - Java Beginners
servlet program problem   i used ur servlet example prg with xml file of helloworld program and i run dat program in tomcat, it shows only... file to run it  Hi Friend, Please clarify your problem. Thanks
Eclipse hibernate problem
Eclipse hibernate problem  hie..i've just started a basic hibernate application using eclipse helios.I have added the jars,configured the xml files...;Hibernate Eclipse Integration Hibernate Tutorials
server problem - Hibernate
server problem  dear sir please give me best soloution how run hibernate and spring application on jboss and weblogic10.1.0 sever and compile thanks
i have problem in that program - JavaMail
i have problem in that program  1. Write a multi-threaded Java program to print all numbers below 100,000 that are both prime and fibonacci number (some examples are 2, 3, 5, 13, etc.). Design a thread that generates prime
hibernate update problem
hibernate update problem  HI, I integrated the struts and hibernate and wrote the following query in the databean to update the user table login time SessionFactory sessionFactory = (SessionFactory)context.getAttribute
Hibernate @ManyToOne persisting problem - Hibernate
Hibernate @ManyToOne persisting problem  hello, In my apllication, there are students and classes. a student can take many classes. So there is OneToMany <--> ManyToOne relationship. Im my case, the best implementation
program to display the first ten terms of the series
program to display the first ten terms of the series  Write a program to display the first ten terms of the following series : 1) 1,-3,5,-7,9..... 2) 3,6,12,24..... 3) 2,5,10,17....... 4) 0,1,2,3,6............ 5) 0,3,8,15

Ads