Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML

Search:
   Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML Facing Programming Problem? Ask Questions?, Browse Latest Questions, Question-Answer Guidelines
Hibernate
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments


 
 

Running First Hibernate 3.0 Example

                         

Hibernate is free open source software it can be download from http://www.hibernate.org/6.html. Visit the site and download Hibernate 3.0. You can download the Hibernate and install it yourself. But I have provided very thing in one zip file. Download the example code and library from here and extract the content in your favorite directory say "C:\hibernateexample". Download file contains the Eclipse project. To run the example you should have the Eclipse IDE on your machine. Start the Eclipse project and select Java Project as shown below.

Click on "Next" button. In the next screen leave the output folder as default "hibernateexample/bin".

Click on the "Finish" button.

Now Open the FirstExample.java in the editor as show below.

Copy  contact.hbm.xml, and hibernate.cfg.xml in the bin directory of the project using windows explorer. To run the example select Run-> Run As -> Java Application from the menu bar as shown below.

This will run the Hibernate example program in Eclipse following output will displayed on the Eclipse Console.

In this section I showed you how to run the our first Hibernate 3.0 example.

                         

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

15 comments so far (
post your own) View All Comments Latest 10 Comments:

Hi Carl,

You get the following exceptions when you do not have the mysql-connector-java-3.0.16-ga-bin.jar and mysql-connector-java-3.1.6-bin.jar in the Java build path
------------------
Exception in thread "main" java.lang.NullPointerException
at roseindia.tutorial.hibernate.FirstExample.main(FirstExample.java:36)
--------------

If you are using eclipse, then Project -> properties - > java Build Path -> libraries tab -> ensure you have MySQL connectors mentioned above here...if not add using the 'Add jars' or 'Add External Jars' option

Posted by saikrishna on Wednesday, 10.15.08 @ 13:56pm | #81095

Thanks to Rose India, and thanks to Deepak, for implementing Hibernate, in such a simple fashion. This program has really worked for me. And helped me to enhance it, for complex application. Thanks again.

If any of you, get problem in inserting data in to contact table.

Create contact table in the following way.

CREATE TABLE `Contact` (

`id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
`firstName` VARCHAR( 50 ) NOT NULL ,
`lastName` VARCHAR( 250 ) NOT NULL ,
`email` VARCHAR( 100 ) NOT NULL ,
PRIMARY KEY ( `id` )
) TYPE = MYISAM ;

Posted by Pratap on Thursday, 10.9.08 @ 16:05pm | #80980

You have to create the table for contact for this to work

CREATE TABLE `Contact` (
`id` int(11) NOT NULL default '0',
`firstname` varchar(20) NOT NULL default '',
`lastname` varchar(20) NOT NULL default '',
`email` varchar(30) default NULL,
PRIMARY KEY (`id`)
) TYPE=MyISAM;

Posted by Amro on Wednesday, 09.17.08 @ 18:10pm | #80100

If you are getting nullpointer then there is problem like include all the jar files which are need for hibernate then it will work fine
required jar files for hibernate are:

hibernate3.jar
dom4j.jar
commons-logging.jar
commons-collections.jar
cglib.jar
concurrent.jar
derby-10.1.2.1.jar
jta1.0.1.jar

Posted by preeti on Monday, 09.15.08 @ 17:15pm | #79588

Reply to the questions asked in the forum(after the question).Make the tutorial as small as possible. I downloaded the tutorial and I am able to see many unwanted things which are not required to run a simple program(it may confuse). I too had the same problem which a user has already asked. If you would have answered to his question means i might not have asked the same question. My problem is
(I ran the application and got output as shown in tutorial. but it did not insert any record in database.)

Posted by thiagarajan on Saturday, 09.13.08 @ 14:12pm | #79102

For some reason, my application didn't insert any data into the table. What's wrong?

Posted by handreach on Sunday, 09.7.08 @ 04:06am | #77610

I am getting the following error when I try to run the FirstExample.java in eclipse.

Exception in thread "main" java.lang.NullPointerException
at roseindia.tutorial.hibernate.FirstExample.main(FirstExample.java:36)

Does anyone has a fix for this?

Posted by Carl on Wednesday, 09.3.08 @ 23:38pm | #77021

its really working ... good job..guys..

Posted by shyam on Friday, 08.15.08 @ 11:33am | #72930

while implementing first hibernate code i am getting NullPointerException in main.

Posted by Tejashree D. Bhanawala on Thursday, 08.14.08 @ 16:32pm | #72820

I ran the application and got output as shown in tutorial. but it did not insert any record in database.

I am using oracle 10g and my setting is
<property name="dialect">org.hibernate.dialect.OracleDialect</property>
is it wrong ?

Posted by sandeep on Wednesday, 06.4.08 @ 16:18pm | #62081

Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.