Frameworks| Hibernate| Struts| JSF| JavaFX| Ajax| Spring| DOJO| JDO| iBatis| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest 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.

 

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 new screen, enter "hibernateexample" as project name and browse the extracted directory "C:\hibernateexample". 

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.

                         

» View all related tutorials
Related Tags: sql c hibernate api query com inheritance class server collections table date select update delete object insert style io connection

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

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

Please add the following line right after the session.Save();
session.beginTransaction().commit();
this will solve the issue.

Posted by Asa on Sunday, 04.5.09 @ 09:53am | #86515

I've also tried the Firstexample.java neither it doesn't insert records to the data base nor it doesn't show any errors.I've had my hibernate.dfg.xml up to date.

Posted by Asa on Sunday, 04.5.09 @ 09:40am | #86514

you have two way:
1.
Transaction tx = session.beginTransaction();//write it
System.out.println("Inserting Record");
Event event = new Event();
event.setId("16");
event.setName("RUNIT2");
session.save(event);
tx.commit();//write it

2.
<hibernate-configuration>
<session-factory>
....
....
<property name="connection.autocommit">true</property> -->add this line
</session-factory>

Posted by thuynguyena1 on Friday, 12.19.08 @ 01:24am | #82955

problem parsing configuration/hibernate.cfg.xml
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" java.lang.NullPointerException
at roseindia.tutorial.hibernate.FirstExample.main(FirstExample.java:38)

Hi Am getting the above error, i am using sql server 2000..
can anybody pls help me..

Posted by lancer on Wednesday, 12.17.08 @ 00:10am | #82847

java.lang.UnsupportedClassVersionError: roseindia/tutorial/hibernate/FirstExample (Unsupported major.minor version 49.0)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:539)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
Exception in thread "main"

--------Any ideas?------------------

Posted by Xiaoying Lin on Friday, 12.5.08 @ 02:34am | #82431

I am using hibernate3.1 and postgresql server I am geting following error
org.hibernate.exception.GenericJDBCException: Cannot open connection

my hibernate.cfg.xml is

<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.driver_class">org.postgresql.Driver</property>
<property name="connection.url">jdbc:postgresql://192.122.1.5/ilsmwblank</property>
<property name="connection.username">TOLdb</property>
<property name="connection.password">TOLdb</property>

<mapping resource="ils/ownshop/stock/business/InstructionSheet.hbm.xml"/>

</session-factory>
</hibernate-configuration>

How i solve it

Posted by Jitendra Kumawat on Tuesday, 12.2.08 @ 23:13pm | #82301

While Running this FirstExample I'm getting NullPointer Exception.

Can any one help me out in this error Please.

Thanks In advance.

--Saritha.

Posted by saritha on Saturday, 10.4.08 @ 21:33pm | #80897

09/23/08
How to insert record to database(MySql) using servlet....

Posted by Abelardo T. Pangantihon on Tuesday, 09.23.08 @ 14:01pm | #80623

I am new to hibernate. During running of my first program I got the problem

Initial SessionFactory creation failed.java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
Exception in thread "main" java.lang.ExceptionInInitializerError
at InitSessionFactory.<clinit>(InitSessionFactory.java:40)
at Main.main(Main.java:18)
Caused by: java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:110)
at InitSessionFactory.<clinit>(InitSessionFactory.java:36)
... 1 more
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
... 3 more
Java Result: 1

I am using NetBeans6.0, hibernate3.0 and MySQL Server

Please help me it is very urgent

Posted by priyanka on Monday, 09.22.08 @ 22:01pm | #80611

in Insurance.hbm.xml file u r not mapped with actual pojo

any issues contact with mail

psree1982@yahoo.co.in

Posted by sree on Friday, 09.19.08 @ 10:27am | #80469

Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

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 | Flex 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.