Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML
 
 
Hot Web Programming Job

 

Tutorial Categories: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML


 

Java Tutorials

Core Java
JSP
Servlet
JDBC
Hibernate
Struts 1
Struts 2
JSF
Spring
J2EE
J2ME
Web Services
Ajax
Dojo
MySQL
Latest Comments
•Good one ...But Mi
•ATA-S2 Ip configur
•Nice article
•Create Exe File
•i want struts2 IDE
  All Comments...
 

 

 
Struts Tutorials
*Stuts TOC
*Apache Struts Introduction
* Struts Controller
* Struts Action Class
* Struts ActionFrom Class
* Using Struts HTML Tags
*Struts Validator Framework    
*Client Side Address Validation    
*Struts Tiles
*tiles-defs.xml
*Struts DynaActionForm
*Struts File Upload
*Struts DataSource
*AGGREGATING ACTIONS
*Internationalization
Struts Resources
*Struts Books
*Struts Articles
*Struts Frameworks
*Struts IDE
*Struts Alternative
*Struts Links
*Struts Presentations
*Struts Projects
*Struts Software
*Struts Reference
*Struts Resources
*Other Struts Tutorial
Visit Forum! Post Questions!
Jobs At RoseIndia.net!

Have tutorials?
Add your tutorial to our Java Resource and get tons of hits.

We offer free hosting for your tutorials. and exposure for thousands of readers. drop a mail
roseindia_net@yahoo.com
 
   

 
Join For Newsletter

Powered by groups.yahoo.com
Visit Group! Post Questions!

Hibernate Runningexample

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

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

Current Comments

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

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

Hi kruti,

Hope ur problem is solved, in case if its not, just add the required libraries in ur buildpath.To run hibernate pgm properly, u need to add the required libraries in the projects buildpath.

Posted by shruthi on Tuesday, 03.18.08 @ 19:50pm | #53207

when i am trying to run hibernate factory class in debug mode then on buildsessionFactory line i am getting error that "The hibernate3.jar source not found"

pls tell me how to solve this

Posted by kruti on Friday, 03.7.08 @ 12:13pm | #51815

Hi Faaud,

You can resolve your problem below problem
------------------------------------------
Exception in thread "main" java.lang.NoClassDefFoundError: net.sf.cglib.core.DebuggingClassWriter$1
------------------------------------------

by doing this:

You have add cglib-2.1.3.jar file into your class file.

OR

If you are working with eclipse 3.0 or 3.1 then this jar file should be added to user library.

OR

go to PROJECT - > PROPERTIES -> JAVA BUILD PATH -> LIBRARIES -> Add External Jars ->
define the path for this jar file.

Now i think you woun't get any error.

Posted by Subnesh on Monday, 03.3.08 @ 14:19pm | #51131

When I run code of sample example at line :

sessionFactory = new Configuration().configure().buildSessionFactory();

I get following error:

Exception in thread "main" java.lang.NoClassDefFoundError: net.sf.cglib.core.DebuggingClassWriter$1
at java.lang.Class.initializeClass(libgcj.so.8rh)
at net.sf.cglib.core.DebuggingClassWriter.toByteArray(DebuggingClassWriter.java:66)
at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:26)
at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:215)
at net.sf.cglib.core.KeyFactory$Generator.create(KeyFactory.java:145)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:117)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:108)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:104)
at org.hibernate.impl.SessionFactoryImpl.<clinit>(SessionFactoryImpl.java:308)
at java.lang.Class.initializeClass(libgcj.so.8rh)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1043)
at FirstExample.main(FirstExample.java:21)
Caused by: java.lang.ClassNotFoundException: org.objectweb.asm.util.TraceClassVisitor not found in gnu.gcj.runtime.SystemClassLoader{urls=[file:/home/nis/batch2007/FAnwar/workspace/Test/New/bin/,file:/home/nis/batch2007/FAnwar/workspace/hibernate/lib/ant-1.6.2.jar,file:/home/nis/batch2007/FAnwar/workspace/hibernate/lib/ant-antlr-1.6.2.jar,file:/home/nis/batch2007/FAnwar/workspace/hibernate/lib/ant-junit-1.6.2.jar,file:/home/nis/batch2007/FAnwar/workspace/hibernate/lib/ant-launcher-1.6.2.jar,file:/home/nis/batch2007/FAnwar/workspace/hibernate/lib/antlr-2.7.4.jar,file:/home/nis/batch2007/FAnwar/workspace/hibernate/lib/ant-swing-1.6.2.jar,file:/home/nis/batch2007/FAnwar/workspace/hibernate/lib/c3p0-0.8.5.jar,file:/home/nis/batch2007/FAnwar/workspace/hibernate/lib/cglib-full-2.0.2.jar,file:/home/nis/batch2007/FAnwar/workspace/hibernate/lib/cleanimports.jar,file:/home/nis/batch2007/FAnwar/workspace/hibernate/lib/commons-collections-2.1.1.jar,file:/home/nis/batch2007/FAnwar/workspace/hibernate/lib/commons-logging-1.0.4.jar,file:/home/nis/batch2007/FAnwar/workspace/hibernate/lib/concurrent-1.3.2.jar,file:/home/nis/batch2007/FAnwar/workspace/hibernate/lib/connector.jar,file:/home/nis/batch2007/FAnwar/workspace/hibernate/lib/dom4j-1.5.2.jar,file:/home/nis/batch2007/FAnwar/workspace/hibernate/lib/ehcache-1.1.jar,file:/home/nis/batch2007/FAnwar/workspace/hibernate/lib/hibernate3.jar,file:/home/nis/batch2007/FAnwar/workspace/hibernate/lib/jaas.jar,file:/home/nis/batch2007/FAnwar/workspace/hibernate/lib/jacc-1_0-fr.jar,file:/home/nis/batch2007/FAnwar/workspace/hibernate/lib/jaxen-1.1-beta-4.jar,file:/home/nis/batch2007/FAnwar/workspace/hibernate/lib/jboss-cache.jar,file:/home/nis/batch2007/FAnwar/workspace/hibernate/lib/jboss-common.jar,file:/home/nis/batch2007/FAnwar/workspace/hibernate/lib/jboss-jmx.jar,file:/home/nis/batch2007/FAnwar/workspace/hibernate/lib/jboss-remoting.jar,file:/home/nis/batch2007/FAnwar/workspace/hibernate/lib/jboss-system.jar,file:/home/nis/batch2007/FAnwar/workspace/hibernate/lib/jdbc2_0-stdext.jar,file:/home/nis/batch2007/FAnwar/workspace/hibernate/lib/jgroups-2.2.7.jar,file:/home/nis/batch2007/FAnwar/workspace/hibernate/lib/jta.jar,file:/home/nis/batch2007/FAnwar/workspace/hibernate/lib/junit-3.8.1.jar,file:/home/nis/batch2007/FAnwar/workspace/hibernate/lib/log4j-1.2.9.jar,file:/home/nis/batch2007/FAnwar/workspace/hibernate/lib/mysql-connector-java-3.0.16-ga-bin.jar,file:/home/nis/batch2007/FAnwar/workspace/hibernate/lib/mysql-connector-java-3.1.6-bin.jar,file:/home/nis/batch2007/FAnwar/workspace/hibernate/lib/oscache-2.1.jar,file:/home/nis/batch2007/FAnwar/workspace/hibernate/lib/proxool-0.8.3.jar,file:/home/nis/batch2007/FAnwar/workspace/hibernate/lib/swarmcache-1.0rc2.jar,file:/home/nis/batch2007/FAnwar/workspace/hibernate/lib/versioncheck.jar,file:/home/nis/batch2007/FAnwar/workspace/hibernate/lib/xerces-2.6.2.jar,file:/home/nis/batch2007/FAnwar/workspace/hibernate/lib/xml-apis.jar], parent=gnu.gcj.runtime.ExtensionClassLoader{urls=[], parent=null}}
at java.net.URLClassLoader.findClass(libgcj.so.8rh)
at gnu.gcj.runtime.SystemClassLoader.findClass(libgcj.so.8rh)
at java.lang.ClassLoader.loadClass(libgcj.so.8rh)
at java.lang.ClassLoader.loadClass(libgcj.so.8rh)
at java.lang.Class.forName(libgcj.so.8rh)
at java.lang.Class.initializeClass(libgcj.so.8rh)
...11 more

Posted by Faaud on Thursday, 02.28.08 @ 19:07pm | #50586

when i tried the example program with transaction autocommited,i am still getting message like
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Inserting Record
Hibernate: insert into CONTACT (FIRSTNAME, LASTNAME, EMAIL, ID) values (?, ?, ?, ?)
Could not execute JDBC batch update

Posted by panbil on Thursday, 02.28.08 @ 14:59pm | #50403

At the time of working with this example:
- table gets created in database
- but no record is inserted

The given below is the solution for the Porblem:

In your FirstExample.java, the transaction should be started explicitly and after saveing your contact details transaction should be commited explicitly.


write below lines before the doing anything with your contact class.
-----------------------------------------------
tx = session.beginTransaction();

//Create new instance of Contact and set values in it by reading them from form object
System.out.println("Creating New Contact detail.");
Contact contact = new Contact();
System.out.println("providing contact details");
contact.setId(6); // Primary key has to be unique for every record inserted!
contact.setFirstName("subnesh");
contact.setLastName("sharma");
contact.setEmail("subnesh@gmail.com");
session.save(contact);
tx.commit();
System.out.println("Contact saved into database successfully");
------------------------------------------------


or

rather then making changes in your FirstExample.java (use same code as privided in this tutorial), you can add new property to hibernate.cfg.xml file with below code:

<property name="hibernate.connection.autocommit"> true </property>
------------------------------------


Posted by subnesh on Wednesday, 02.27.08 @ 11:44am | #50282

Its really nice example to the things in a repid way. Understandable and more focus is on "how to do mappings".
Good work done

As some other developers suggested to do some changes in the code, i made them and then got the data in database.

Thanks again buddy :)

Posted by Subnesh on Wednesday, 02.27.08 @ 11:19am | #50277

hi i run that program. the output in the console came as shown in the tutorial. but when i cheak the database nothing is inserted in that. did any one cheaked it. please give me suggestion. because i am new to hibernate and to java

Posted by sandeep on Tuesday, 02.26.08 @ 06:35am | #50098

Thank you. It is good to start with. I started with this example, faced some problems, but finally I got through.

Posted by Pradeep Kumar on Thursday, 02.14.08 @ 17:02pm | #48265

it is really nice tutorial for bigners;

Posted by vishvadeep on Wednesday, 02.13.08 @ 21:08pm | #48167

Thanks for providing source code, of hibernate
its working fine...

only small modification is in hibernate.cfg.xml
we need to include
<property name=
"connection.autocommit">true</property>

Thanks
Shrinivas

Posted by shrinivas on Wednesday, 02.13.08 @ 11:15am | #48116

I think you need these statements in your hibernate.cfg.xml. so that it commits in the database

<!-- Set AutoCommit to true -->
<property name="connection.autocommit">
true
</property>

Posted by lovely on Friday, 02.8.08 @ 04:17am | #47555

U gave me one Zip file which contains Hibernate Source code. i Download it and saved it as u said and tried to run that program using MyEclipse IDE. I got the result that the record is inserted successfully. But in database its not inserted but it creates new table. whats the porblem? please clarify me soon...

Posted by Christopher Rajesh on Monday, 02.4.08 @ 12:07pm | #47178

U gave me one Zip file which contains Hibernate Source code. i Download it and saved it as u a said and tried to run that program using MyEclipse IDE. I got the result that the record is inserted successfully. But in database its not inserted but it creates new table. whats the porblem? please clarify me soon...

Posted by Christopher Rajesh on Monday, 02.4.08 @ 12:05pm | #47177


Hi,please anyone help..i m getting an error like this..

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Cannot open connection

Posted by vidhya on Monday, 01.28.08 @ 13:29pm | #46386

I believe there are 2 errors in this tutorial.

1) You have to create the "hibernatetutorial" database in MySQL. The command is "create database hibernatetutorial" The hibernatetutorial database is referenced in file hibernate.cfg.xml in line "<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/hibernatetutorial</property>".

2) Since this tutorial was written a while ago, I'm using a different version of MySQL than the author of this tutorial, and the default behavior of MySQL may have changed since then. At first executing FirstExample.java would create tables Contact, Book, and Insurance, but no records were inserted in any of the tables. The problem is that we need to begin a transaction, then save the session, and then commit the transaction.

As posted by nidhin:

The following line need to be added right after session open in try block of FirstExample.java

org.hibernate.Transaction tx = session.beginTransaction();

Also tx.commit(); need to be added after saving session at the end of try block to get the record in to the database.

I modified the class to the following, and it works for me.


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;
org.hibernate.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();
tx = session.beginTransaction();

//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); // Primary key has to be unique for every record inserted!
contact.setFirstName("John");
contact.setLastName("Doe");
contact.setEmail("noemail@yahoo.com");
session.save(contact);
tx.commit();
System.out.println("Done");
}catch(Exception e){
System.out.println(e.getMessage());
e.printStackTrace();
if (tx != null) {
System.out.println("Rolling back transaction");
tx.rollback();
}
} finally {
try {
// Actual contact insertion will happen at this step
session.flush();
session.close();
} catch (Exception e){
e.printStackTrace();
}

}

}
}

Posted by wan on Thursday, 01.17.08 @ 13:34pm | #45417

The hibernate tutorial which you have displayed is understandable. It makes even a fresher to understand things better.

Posted by Bala on Tuesday, 01.8.08 @ 12:17pm | #44778

just check ur jdk/jre settings and make sure ur java paths are set correctly

Posted by dinakaransp on Thursday, 01.3.08 @ 09:48am | #44413

Hi, Thank u very much. A good start for beginner. I am using eclipse. I have written same code but I am using the postgresql and have change the hibernate.cng.xml according to the DBMS. But I got following error. Would you like to help me to remove this error. Thanks

Exception in thread "main" java.lang.NullPointerException
at example.hibernate.FirstExample.main(FirstExample.java:30)

Posted by Ali on Thursday, 12.27.07 @ 04:11am | #43893

i will open transaction after openSession and data is insert into database. Oh very interesting.

Posted by desengel on Saturday, 12.22.07 @ 12:50pm | #43352

is it must to have eclipse on system to run hibernate example..?

i have java,mysql,hibernate intstalled on my machine...then do i still need eclipse..?

will i not b able to run this code without eclipse..?

looking fwd for ur help..its urgent

thanx in advance

m waiting for replies..

Posted by gunjan on Thursday, 12.20.07 @ 11:30am | #43077

excellent

Posted by laxman on Saturday, 12.15.07 @ 19:05pm | #42517

Everig is working right but no out put in data base

Posted by nidhin on Thursday, 12.6.07 @ 16:53pm | #41441

Following line need to be added right after session open in try block of FirstExample.java

org.hibernate.Transaction tx = session.beginTransaction();

Also tx.commit(); need to be added after saving session at the end of try block to get the record in to the database.

This should work. It worked for me.

Posted by RAJAN P MEHTA on Sunday, 12.2.07 @ 07:43am | #41082

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Inserting Record
Done
Exception in thread "main" org.hibernate.exception.GenericJDBCException: Cannot open connection
at org.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:92)
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:80)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
at org.hibernate.jdbc.AbstractBatcher.openConnection(AbstractBatcher.java:384)
at org.hibernate.jdbc.JDBCContext.connect(JDBCContext.java:141)
at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:88)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:73)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:66)
at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:130)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1809)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:2171)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:46)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:223)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:136)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:669)
at roseindia.tutorial.hibernate.FirstExample.main(FirstExample.java:36)
Caused by: java.sql.SQLException: Unable to connect to any hosts due to exception: java.net.ConnectException: Connection refused: connect

** BEGIN NESTED EXCEPTION **

java.net.ConnectException
MESSAGE: Connection refused: connect

STACKTRACE:

java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:124)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:225)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:1783)
at com.mysql.jdbc.Connection.<init>(Connection.java:450)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:411)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110)
at org.hibernate.jdbc.AbstractBatcher.openConnection(AbstractBatcher.java:381)
at org.hibernate.jdbc.JDBCContext.connect(JDBCContext.java:141)
at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:88)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:73)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:66)
at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:130)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1809)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:2171)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:46)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:223)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:136)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:669)
at roseindia.tutorial.hibernate.FirstExample.main(FirstExample.java:36)


** END NESTED EXCEPTION **


at com.mysql.jdbc.Connection.createNewIO(Connection.java:1851)
at com.mysql.jdbc.Connection.<init>(Connection.java:450)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:411)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110)
at org.hibernate.jdbc.AbstractBatcher.openConnection(AbstractBatcher.java:381)
... 15 more

Posted by raghunath on Thursday, 11.29.07 @ 22:31pm | #40918

Develop a hibernate application in eclipse:

step1: Selec the new project (java project)
right click choose build path under this configure build path. A properties of ur project window open, then click libraries add the jars then choose order and export , select all then click ok.

step two: right click ur project select new then other then click hibernate.cfg.xml then type the database url and driver and username and password details.After that run the hibernate.cfg.xml file automatically created by eclipse.

step 3: create a hibernate reverse engineering xml file (same as step 2) it is for create hbf and pojo files creation automatically.(u can configure the database table in this step)

Posted by Javed.N on Monday, 11.19.07 @ 18:40pm | #37837

I am gettin this error with oracle dilect

please help me out


org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
at org.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:92)
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:80)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:161)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:226)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:136)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:669)
at roseindia.tutorial.hibernate.FirstExample.main(FirstExample.java:36)
Caused by: java.sql.BatchUpdateException: ORA-00942: table or view does not exist

at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:367)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:8738)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:57)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:154)
... 6 more
Exception in thread "main"

Posted by abhijeet.iyengar@gmail.co on Monday, 11.19.07 @ 16:07pm | #37819

I need the info i.e
hql support all sql statements that works with DataBase(any).
I need some Syntax for joins.
using Sql is better or Hql is better for an application.
Regards,
Ravikumar.k

Posted by RaviKumar.kapa on Friday, 11.16.07 @ 17:48pm | #37569

Hi all,
the only point missing on this page is that we also need mysql db installed to run this tute. The required JDBC drives are already in the lib dir.
If you are having problems in running this tute or don't want to use eclipse or mysql then the tutorial on hibnernate's website is for you. It uses hipersonic db and no IDE.

Posted by Rishabh on Tuesday, 11.13.07 @ 09:44am | #37177

Instead of Catching Exception catch Throwable.
It will show that u need to add more jar files in the classpath

Posted by Ritesh on Monday, 11.12.07 @ 17:25pm | #36969

Hi...

Hopefully you all ll b fine.

I have run the first hibernateexample successfully, and output in the console window is same as told in tutorial... but the issue is there is no record in the database table "Contact"...

Can you plz help me out here...

Thanks in advance...
Imran

Posted by Imran on Monday, 11.12.07 @ 13:33pm | #36951

Hi All,

Just want to add something. I did this example and it work for me until now. It’s just initially I get confused with database. So people please create database hibernatetutorial. That is in mysql and if there is password there then open then mentioned that in your hibernate.hbm.xml file. After doing so it will give exactly same result as shown above.
Hope it helps

Cheers.

Posted by nature on Tuesday, 11.6.07 @ 09:44am | #35848

I think you haven't given your mysql password in hibernate.cfg.xml

Posted by Wahidhar Reddy on Friday, 10.5.07 @ 22:15pm | #31852

I am getting error in 'Session Factory' for update telling not finding contact.hbm.xml.Please help me.

Posted by Rajib on Tuesday, 09.25.07 @ 16:29pm | #29321

I am getting this error continously
how to remove it.
If any body know please send me
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
could not instantiate CacheProvider: org.hibernate.cache.NoCacheProvider
Exception in thread "main" java.lang.NullPointerException
at roseindia.tutorial.hibernate.FirstExample.main(FirstExample.java:36)

Posted by Radha on Thursday, 09.20.07 @ 11:48am | #28179

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

this is the error i am getting
can anyone help me why i am getting this error?

Posted by sai on Wednesday, 09.19.07 @ 14:45pm | #27839

Hi all

It is a fine site for develpers so carry on your efforts to facilitate them.

Thanks a lot.

Posted by sajjad on Saturday, 09.8.07 @ 16:33pm | #26426

Oh dear is it not possible to show a first example without eclipse?

It will be fine but has nothing to do with hibernate. If you had several problems, eclipse is also a point of failure.

Regards
Marc

Posted by Marc on Thursday, 08.23.07 @ 14:58pm | #23972

hi all

i tried thias example..chnaged a little bit for my informix db ,am thinking informix does not support or something. pls help

java.lang.AbstractMethodError: com.informix.jdbc.IfxDatabaseMetaData.supportsResultSetType(I)Z
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:121)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1497)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1041)
at roseindia.tutorial.hibernate.FirstExample.main(FirstExample.java:23)
Exception in thread "main"

Posted by sri on Saturday, 08.11.07 @ 02:48am | #23131

very nice site, it is very helpfull for developers ok carry on

Posted by Gopu on Friday, 08.10.07 @ 14:52pm | #23097

folks,
not sure but may I am getting error "The selection does not contain a main type" though I have defined main method inside the class.
Anyone help would be highly appreciable.

Pankaj

Posted by Pankaj on Thursday, 08.9.07 @ 19:52pm | #23035

I keep getting this error message :
Any help anyone?

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
could not instantiate CacheProvider: org.hibernate.cache.NoCacheProvider
Exception in thread "main" java.lang.NullPointerException
at roseindia.tutorial.hibernate.FirstExample.main(FirstExample.java:36)

Posted by Shawn on Wednesday, 08.8.07 @ 15:20pm | #22933

Exception in thread "main" java.lang.NoClassDefFoundError: org/dom4j/DocumentException
at FirstExample.main(FirstExample.java:21)

Posted by Prahlad on Monday, 08.6.07 @ 17:25pm | #22769

Hi,
I dont get this and neither I can see the rows in the db.
Hibernate: insert into CONTACT (FIRSTNAME, LASTNAME, EMAIL, ID) values (?, ?, ?, ?)

I just get till the "Done"
Could anyone let me know the problem

Posted by Nag on Friday, 08.3.07 @ 05:32am | #22540

i run the application in eclipse and got the following output,

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Inserting Record
Done
Hibernate: insert into CONTACT (FIRSTNAME, LASTNAME, EMAIL, ID) values (?, ?, ?, ?)


but when i opened table contact ,here no data are inserted, so what is wrong here plz let me know.

i am using mySql 5, pls help me...

Posted by ardi on Thursday, 08.2.07 @ 12:07pm | #22472

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();
org.hibernate.Transaction tx = session.beginTransaction();
//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);
tx.commit();
session.flush();
session.close();
System.out.println("Done");
}catch(Exception e){
System.out.println(e.getMessage());
}finally{
// Actual contact insertion will happen at this step
}

}
}


log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Inserting Record
could not insert: [roseindia.tutorial.hibernate.Contact]

I cannot still insert records but I use exadel to add hibernate capabilities. Please let me know what happen. thanks

Posted by matthew on Sunday, 07.29.07 @ 20:08pm | #22168

Here transaction has to started.


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();
org.hibernate.Transaction tx = session.beginTransaction();
//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);

tx.commit();
session.flush();
session.close();

System.out.println("Done");
}catch(Exception e){
System.out.println(e.getMessage());
}finally{
// Actual contact insertion will happen at this step


}

}
}

Posted by Madhu on Tuesday, 07.24.07 @ 21:27pm | #21856

May be you have sent some constraints in the table which restricts your program not to add these enteries in the table, check if you have set autoincrement for your primary key and adding the same key again or get the stack trace using e.printStackTrace() in the catch block to get more generic error details.


Thanks
Amit

Posted by Amit on Tuesday, 07.10.07 @ 18:27pm | #21031

I followed all the instructions properly.But still i am getting following problems
<i>java.lang.NullPointerException
at FirstExample.main(FirstExample.java:41)
Exception in thread "main" i>
I am using eclipse and have added all the jars in the project.DB2 is my database

Posted by hiba on Tuesday, 07.10.07 @ 15:45pm | #21027

i run the application in eclipse and got the following output,

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Inserting Record
Done
Hibernate: insert into CONTACT (FIRSTNAME, LASTNAME, EMAIL, ID) values (?, ?, ?, ?)


but when i opened table contact ,here no records are inserted, so what is wrong here plz let me know.

i am using mySql 4.0 and setting are as per u have described in the tutorial.

Posted by sandip on Wednesday, 06.20.07 @ 15:49pm | #19782

Inserting Record
Hibernate: insert into CONTACT (FIRSTNAME, LASTNAME, EMAIL, ID) values (?, ?, ?, ?)
Could not execute JDBC batch update

Posted by rajesh on Tuesday, 06.5.07 @ 16:00pm | #18276

i am having follwoing exception:

Initial SessionFactory creation failed.java.lang.NoClassDefFoundError: org/aspectj/lang/Signature
null
Exception in thread "main" java.lang.NullPointerException
at com.FirstExample.main(FirstExample.java:31).

I have done all the things and included all the jars

Posted by Rippon Jalali on Thursday, 05.31.07 @ 11:31am | #17830

I followed all the instructions properly.But still i am getting following problems
<i>Exception in thread "main" java.lang.NullPointerException
at com.FirstExample.main(FirstExample.java:28)</i>
I am using eclipse and have added all the jars in the project.
Deadlines are ending .So please help.Thanks in advance

Posted by Rippon Jalali on Thursday, 05.31.07 @ 10:18am | #17818

Hi
ur material is very useful. but how to execute the application without eclipse ide, say from cmd prompt. and where to place the 2 xml files.

im executing from the cmd prompt and getting the following error:

NoClassDefFoundError: org/apache/commons/logging/LogFactory at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:110)

pls do give a solution

thanks

Posted by Hibernateuser on Saturday, 05.26.07 @ 18:02pm | #17358

I use DB2 Database, with table Contact have ( id - Integer, firstname - varchar(20), lastname - varchar(20), email - varchar(30)). But firstExample don't run, it throw a Exception. And I don't know why ? :( Plz to help me!

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.

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

Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not insert: [roseindia.tutorial.hibernate.Contact]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:59)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1839)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:2171)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:46)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:223)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:136)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:669)
at roseindia.tutorial.hibernate.FirstExample.main(FirstExample.java:36)
Caused by: com.ibm.db2.jcc.b.SqlException: DB2 SQL error: SQLCODE: -204, SQLSTATE: 42704, SQLERRMC: NESAVER.CONTACT
at com.ibm.db2.jcc.b.ig.e(ig.java:1594)
at com.ibm.db2.jcc.b.ig.a(ig.java:1204)
at com.ibm.db2.jcc.c.gb.g(gb.java:140)
at com.ibm.db2.jcc.c.gb.a(gb.java:39)
at com.ibm.db2.jcc.c.w.a(w.java:34)
at com.ibm.db2.jcc.c.vb.f(vb.java:139)
at com.ibm.db2.jcc.b.ig.n(ig.java:1175)
at com.ibm.db2.jcc.b.jg.eb(jg.java:1877)
at com.ibm.db2.jcc.b.jg.d(jg.java:2319)
at com.ibm.db2.jcc.b.jg.W(jg.java:463)
at com.ibm.db2.jcc.b.jg.executeUpdate(jg.java:446)
at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:22)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1823)
... 9 more

Posted by Nesaver on Thursday, 05.24.07 @ 17:30pm | #17160

Here is the solution. In FirstExample.java, Before printing "Inserting Record", we need to create the transaction as "Transaction t = session.beginTransaction();". Then, after the line "session.save(contact)", we need to add the line "t.commit();". After, that we can enjoy the output. The Record will be get inserted in the table.

Posted by Mohanaraj Jagadeesan on Wednesday, 05.23.07 @ 17:57pm | #17098

I got the output printed on the screen exactly what is there in this page. But, the record is not getting inserted in the table. Please do the needfull help.Kind Regards, Mohanaraj. J

Posted by Mohanaraj Jagadeesan on Wednesday, 05.23.07 @ 16:21pm | #17088

I too got the same problem. Now its solved.

solution :
==========

1. place your hibernate.cfg.xml file and the other xml file in your source folder in your project.

for example: if your project name is "hibernateproject" then you will find src folder in your project tree which is the source folder and is mentioned at the time of creating your new project in Eclipse.

2. for null pointer: check all .jar files in your projects classpath whether you have everything or not..

i am sure if you have done this then you dont have any problem..

bye
Murali :)

Posted by MURALI KRISHNA on Saturday, 05.19.07 @ 19:29pm | #16566

I added the following jars
ant-antlr-1.6.5.jar
asm.jar
cglib-2.1.3.jar
commons-collections-2.1.1.jar
commons-logging-1.0.4.jar
dom4j-1.6.1.jar
ehcache-1.2.3.jar
hibernate3.jar
jta.jar
log4j-1.2.11.jar
ojdbc14.jar


Also Added
session.connection().commit();
after flushing.

Now my records are inserted successfully...

And this tutorial is simply superb for the beginners too.

Thankx

Posted by Sophia on Saturday, 05.19.07 @ 01:12am | #16475

hibernate.cfg.xml shud be ther in BIN directory or WEB-INF ..check it out..

Posted by Sophia on Saturday, 05.19.07 @ 01:07am | #16474

What are the jars i should have under my lib? to avoid Null Pointer Exception.

Posted by Sophia on Friday, 05.18.07 @ 23:09pm | #16467

Hi,

Im getting NullPointerException while running this application..In the line
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();

whats the problem?

Posted by Sophia on Friday, 05.18.07 @ 03:09am | #16318

no solve the NullPointer exception.just place all the jars in the lib folder in your classpath

Posted by Xavier on Wednesday, 05.16.07 @ 17:15pm | #16143

while executing the code. I am getting following error

Insurance is not mapped. [from Insurance insurance]

Any idea ?

Posted by Somnath Pal on Tuesday, 05.15.07 @ 21:55pm | #16025

there is some confusion regarding xml files u've mentioned.pls clarify

Posted by jagadeesh on Friday, 05.11.07 @ 15:15pm | #15640

Hi Raghu,
This error is coming is becuase the your hibernate.cgf.xml is not in your project class path.

Posted by Rishi on Tuesday, 05.1.07 @ 21:32pm | #15138

Hai,All

When i tried to run THE ABOVE CODE
I am getting below Error,Can any one Help me how to reslove

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

Posted by Raghu on Friday, 04.27.07 @ 14:32pm | #15007


I have followed the above instructions and came to see that the same output was printed on the console screen of eclipse. But when i check the database, i came to see that data was not inserted.

What might be the possible reason that. I've configured the xml files in the same way as mentioned in tutorial. But we have to give password to acces the database. So i gave password also in the xml file.

Please help me. It's very very urgent.

Posted by Renjith K.R. on Thursday, 04.26.07 @ 12:32pm | #14958

how to develop the java project in eclips

Posted by sailaja on Wednesday, 04.18.07 @ 14:55pm | #14493

I am geeting this type of error, I have also used the suggestion af this problem given by seeta but can not do this.
I need help urgently so plz help me. I have add all jars.

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
/hibernate.cfg.xml not found

Posted by Avinash on Sunday, 04.15.07 @ 11:02am | #14217

Anyone has idea abt this error in hibernate.
Could not parse mapping document from resource contact.hbm.xml

Posted by Rajat on Thursday, 04.12.07 @ 22:27pm | #13999

Dear any body,
I have followed all the steps which are mensioned in the tutorial. I have paste the both xml files in the source. I have also created hibernatetutorial database. then i have tried to run the hibernateexample class. but it is throwing null pointer exception. please help me to run the this example.


Posted by layak on Friday, 04.6.07 @ 16:28pm | #13466

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
/hibernate.cfg.xml not foundException in thread "main" java.lang.NullPointerException
at Site.FirstExample.main(FirstExample.java:44)

solution
include this in Firstexample.java file
finally {

// Actual contact insertion will happen at this step
if(session != null){
session.flush();
session.close();
}
if(sessionFactory != null)
sessionFactory.close();
}

if you still get errors then include all the jars files.

Posted by seeta on Tuesday, 04.3.07 @ 15:12pm | #13262

i am new to hibernate ,whenever i am running my first hibernate application i am getting the foolowing parsing error ...Could not parse hibernate.cfg.xml

<?xml version="1.0" encoding="utf-8" ?>

<!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="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property>
<property name="connection.url">jdbc:jtds:sqlserver://localhost:1433/nobish</property>
<property name="connection.username">sa</property>
<property name="connection.password">sa</property>


<mapping resource="book/business/book.hbm.xml" />
</session-factory>
</hibernate-configuration>

Posted by Debapriya Maity on Monday, 04.2.07 @ 11:58am | #13177

I AM GETTING HIBERNATE.MAPPINGEXCEPTION
: ERROR READING THE RESOURCE CONTACT.HBM.XML
FILE


PSE GIVE THE SOLUTION ...............





Posted by sankalp saxena on Friday, 03.23.07 @ 12:21pm | #12547

Can anybody show me how to create a SQL Query in MyEclipse for hibernate ...

I need it please ....

Posted by John on Wednesday, 03.14.07 @ 10:01am | #11645

hi ....
Fantastic job out there...
really its a good tutorials

Posted by keshav on Friday, 03.9.07 @ 14:32pm | #11237

Hi Renjith,

Hibernate is driven by XML configuration files to map classes to the database and eliminate need for respective SQL so you will not find this query in a code. It handles all create-read-update-delete operatioin using simple API no SQL.

To insert your data, you need to add two lines here.
session =sessionFactory.openSession();
Transaction tx = session.beginTransaction();
.
.
.
session.save(contact);
tx.commit();

Regards,
Sachin.

Posted by sachin on Thursday, 03.8.07 @ 18:32pm | #11163

to insert data into the Database add the following code:

1) import transaction class

import org.hibernate.Transaction;
2) add the below line after
your session =sessionFactory.openSession();


Transaction tx = session.beginTransaction();

3) add the below line after
this statement session.save(contact);

tx.commit();

4) save, compile and run as java application.

good luck

Mahamud Mahamed

Posted by Mahamud Mahamed on Thursday, 03.8.07 @ 06:41am | #11079

This part has given a clear concept on Hibernate.
Thanks a lot

Posted by Vivek Vishwakarma on Thursday, 03.8.07 @ 03:19am | #11057

Hi,
This is for the first time in my life that i am using Hibernate. I followed the above steps mentioned and then executed the program. I came to see that the program executed succesfully.
I also got a message in the "Console" of Eclipse that,

"Hibernate:insert into contact(FIRSNAME,LASTNAME,EMAIL,ID) values(?,?,?,?)"

Then i checked the database and found that the table "Contact" was created succesfully. But it was empty and the specified values haven't inserted into it.

So i tried to find out where this "insert" statement is being mentioned. But it was in vain.

Can anyone suggest the reason for that problem and where can i find this "insert" query?

Is it possible for the user to specify the query. If yes, where?

Posted by Renjith K. R. on Wednesday, 03.7.07 @ 17:45pm | #11004

Hi i m new to Hibernate when i m executing my hibernate application with eclipse IDE i m getting following exceptional error..

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
/hibernate.cfg.xml not foundException in thread "main" java.lang.NullPointerException
at Site.FirstExample.main(FirstExample.java:44)

Posted by sanjay kumar on Friday, 03.2.07 @ 12:09pm | #10189

Hi guys,
can any one tell me the directory structure and where to place hibenate.cfg.xml and *.hbm.xml files.

Posted by srinivas on Thursday, 03.1.07 @ 13:11pm | #10024

Hi .. Im getting error while running FirstExample of Hibernate is

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

Im using ORACLE9i Database... i have been added all jar files in Lib Directory, added Hibernate2.0 jar and classes-12.zip files etc...

anybody plz help me.... Thank U

Posted by Satyanarayana on Thursday, 03.1.07 @ 12:31pm | #10022

when i run firstexample.java program i got

Cannot open connection
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.

please help me!

Thanks in advance
Shain

Posted by shain on Tuesday, 02.27.07 @ 15:38pm | #9834

Hi ,
Those who could not insert data to the database, add the transaction support as shown below. It works for me

session =sessionFactory.openSession();
Transaction tx = session.beginTransaction();
.....................
.....................
session.save(contact);
tx.commit();
//session.close();

-Suraj

Posted by Suraj Batuwana on Monday, 02.26.07 @ 13:56pm | #9649

Unhandled Exception thrown: class java.lang.NullPointerException
[2/22/07 18:09:51:989 IST] 66eac2b3 WebGroup E SRVE0026E: [Servlet Error]-[]: java.lang.NullPointerException

at SessionFactory sessionFactory = configuration.buildSessionFactory();

Posted by vandana on Thursday, 02.22.07 @ 18:11pm | #8891

I am getting :


Inserting Recordorg.hibernate.impl.SessionImpl(PersistentContext[entitiesByKey={}] ActionQueue[insertions=[] updates=[] deletions=[] collectionCreations=[] collectionRemovals=[] collectionUpdates=[]])
Hibernate: select contact_.ID, contact_.FIRSTNAME as FIRSTNAME0_, contact_.LASTNAME as LASTNAME0_, contact_.EMAIL as EMAIL0_ from CONTACT contact_ where contact_.ID=?
Done
Hibernate: insert into CONTACT (FIRSTNAME, LASTNAME, EMAIL, ID) values (?, ?, ?, ?)
sessionorg.hibernate.impl.SessionImpl(PersistentContext[entitiesByKey={EntityKey[roseindia.tutorial.hibernate.Contact#6]=roseindia.tutorial.hibernate.Contact@48edb5}] ActionQueue[insertions=[] updates=[] deletions=[] collectionCreations=[] collectionRemovals=[] collectionUpdates=[]])


but when I see database ,no data is getting inserted

Posted by Hitamsu on Tuesday, 02.20.07 @ 15:13pm | #8476

Hi,

I'm getting
"Exception in thread main java.lang.NullPointerException"
while executing the above Program. Can you please help me in solving the problem.

Posted by Dileep on Sunday, 02.11.07 @ 10:54am | #7313

to avoid the nullpointerexception you have to add the following .jar-files to the "java build path" - libraries:

* hibernate3.jar
* all from the subdirectory /lib
* mysql-connector-java-5.0.4-bin.jar (jdbc-driver)
* the JRE of course :)

good luck

Posted by vbnm on Sunday, 02.11.07 @ 04:21am | #7278

Hi,
I am getting the following error when i try to run FirstExample.

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

Please help!!!

Posted by suresh on Thursday, 02.1.07 @ 00:35am | #5015

Hi,
I am getting the following error when i try to run FirstExample.

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

Please help!!!

Posted by Alex on Thursday, 01.25.07 @ 02:41am | #4276

Hi to run above programm need mysql Database, mysql-connector-java-3.1.12-bin.jar file in classpath.

Posted by samba on Wednesday, 01.17.07 @ 11:16am | #3654

Hi,
I am getting the following error when i try to run FirstExample.

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

Please help!!!

Posted by Aruna on Wednesday, 01.17.07 @ 00:52am | #3645

Everything working fine. but i am n't being able to view data in database..

i am using oracle 9 as database & classes12.zip as oracle class.

Am i missing anything..

Posted by BHopl Sajwan on Monday, 01.15.07 @ 22:35pm | #3557

Many Thanks . It was very useful to understand and execute a sample application. After few minor changes it is working fine

Posted by Muniasamy on Thursday, 01.11.07 @ 15:14pm | #3197

Please explain the attributes of hibernate map.

Posted by Akanksha on Wednesday, 01.10.07 @ 11:19am | #3100

hi

i placed the hibernate application in eclipse.
while running FirstExample.java i got
java.lang.NullPointerException
at roseindia.tutorial.hibernate.FirstExample.main(FirstExample.java:31)
Exception in thread "main"

anybody can solve this problem.....

Posted by lakshmi on Tuesday, 01.9.07 @ 18:38pm | #3053

When trying to run FirstExample I'm getting compilation problems like:

Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Session cannot be resolved to a type
SessionFactory cannot be resolved to a type
Configuration cannot be resolved to a type

at roseindia.tutorial.hibernate.FirstExample.main(FirstExample.java:17)

Posted by Sisir on Monday, 01.8.07 @ 18:41pm | #2971

Hi,

Its a good tutorial to start with. However, am unable to connect it to SqlServer 2005 or 2000. Can anyone please let me know the configurations which I need to do for the same. I cudnt find the driver class to connect it with SqlServer 2005 or 2000

Posted by Vibhor Bhatia on Tuesday, 01.2.07 @ 13:34pm | #2409

when i run firstexample.java program i got



Dec 23, 2006 8:40:03 PM org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.2.1
Dec 23, 2006 8:40:03 PM org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
Dec 23, 2006 8:40:03 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : cglib
Dec 23, 2006 8:40:03 PM org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
Dec 23, 2006 8:40:03 PM org.hibernate.cfg.Configuration configure
INFO: configuring from resource: /hibernate.cfg.xml
Dec 23, 2006 8:40:03 PM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: /hibernate.cfg.xml
Dec 23, 2006 8:40:04 PM org.hibernate.util.XMLHelper$ErrorLogger error
SEVERE: Error parsing XML: /hibernate.cfg.xml(2) The processing instruction target matching "[xX][mM][lL]" is not allowed.
Could not parse configuration: /hibernate.cfg.xml

this error how can i cure it?


plz tel me any one!

Posted by krishnan on Saturday, 12.23.06 @ 20:54pm | #1514

I need the execution of hibernate example in Eclipse IDE.ANybody please provide the doccumentation.

Posted by madhavi on Tuesday, 12.12.06 @ 18:15pm | #900

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"

--------WHY?------------------

Posted by LeToan on Monday, 12.11.06 @ 15:39pm | #845

Hi,

Could anyone tell me what r the pre-requisits to run above mentioned Hibernate 3.0 example.

I mean, wht is the database, version and type of driver and all.

Thanks and regards
Sravan

Posted by Shravan on Monday, 12.11.06 @ 12:50pm | #761

im gettting error like

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


when running FirstExample.java


any body help me???

Thanks in Advance

Posted by raju on Wednesday, 12.6.06 @ 19:27pm | #514

hello iam new to hibernate.i need some help.i want to pass one parameter through java programme.it goes to data base and retrieve the data from database
Table Fields:
Tyep:Mr35
Prefix:MR35
format:YYYYMMDDNNNN
Subfix:ABC
Last_No:0,1,2,
public method:String get DocumentNo(String Type)
{
return type(MR35200612010001ABC)
}

Posted by GiriBabu on Saturday, 12.2.06 @ 09:50am | #347

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.

Back to Tutorial

 

  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name
Search Tutorials