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

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


 

 

Struts Tutorials

Struts Resources

Visit Forum! Post Questions!
Jobs At RoseIndia.net!

Hibernate Runninge Xample

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

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

Your site is Really Super hints and guide for developers...

Posted by Ramesh on Thursday, 10.14.10 @ 15:39pm | #100282

we may reqiured to update hibernate.cfg.xml file
<property name="hibernate.connection.url">jdbc:mysql://localhost:3307/hibernatetutorial</property>
and also u may reqiured to edit password in this file.

Posted by Dattatray on Sunday, 10.3.10 @ 00:10am | #100020

The code failed as the transction was not created.
Since session.flush() sends the query to database and runs the query. still the code was not working. Please can you help me understanding the code

Posted by Beginner on Saturday, 09.4.10 @ 01:55am | #99359

Thanks Arun!

Posted by Thomas on Saturday, 08.28.10 @ 17:42pm | #99241

very good program.
i am trying to oracle connection. same output generated.
how to implement dynamically....
crate ,insert and deleted

Posted by siva on Thursday, 08.5.10 @ 16:11pm | #98721

package com.jsfvalidation.hibernatefactory;

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

import com.jsfvalidation.hibernate.beans.Contact;

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();
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(3);
contact.setFirstName("Deepak");
contact.setLastName("Kumar");
contact.setEmail("deepak_38@yahoo.com");
session.save(contact);
tx.commit();
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();

}

}
}

Posted by toto on Wednesday, 08.4.10 @ 17:36pm | #98686

run successfully but no record insert anybody know
please help me about it

Posted by mojtaba on Sunday, 07.25.10 @ 16:02pm | #98426

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 Book object
into database..");
Book book = new Book();
book.setStrBookName("Hibernate
Tutorial");
session.save(book);
System.out.println("Book object
persisted to the database.");
tx.commit();
session.flush();
session.close();
}catch(Exception e){
System.out.println(e.getMessage());
}finally{
}

}
}



Please compare your code with this...There you are missing "Transaction " after session instance is created and tx.commit() is missing...I think...Try and let me know......

Posted by Hema on Monday, 06.28.10 @ 04:45am | #97814

I have followed your instructions but am not able to run the application. Is there something special has to be set up in Eclipse?

Posted by Krishnan on Tuesday, 06.15.10 @ 01:08am | #97581

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: Invalid authorization specification message from server: "Access denied for user 'root'@'localhost' (using password: NO)"
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1997)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1906)
at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:2520)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:817)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:1786)
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 dj on Sunday, 04.25.10 @ 17:43pm | #96619

learners may also mistake that it is hibernate which wil create the tabe on its own in the DB... so please include the table creation process

Posted by swapnil on Wednesday, 04.21.10 @ 10:50am | #96526

getting error while running the firstexample in eclipse.
These lines can not be resolved:......


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

Posted by deepmala on Friday, 03.12.10 @ 22:07pm | #95523

In Above example..Always use <property name="connection.autocommit">true</property> in your xml configuration file if you are not using transaction otherwise you will not able to see the record in Database.

Posted by Gaurav on Tuesday, 03.9.10 @ 00:59am | #95403

In Above example..Always use <property name="connection.autocommit">true</property> in your xml configuration file if you are not using transaction otherwise you will not able to see the record in Database.

Posted by Gaurav on Tuesday, 03.9.10 @ 00:58am | #95402

Will it work in Netbeans?

Posted by Anonymoususer on Friday, 03.5.10 @ 22:12pm | #95340

package roseindia.tutorial.hibernate;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
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) {
FirstExample fe = new FirstExample();
Session session = null;
Transaction tx = null;
List list =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();

//Insert or Update
System.out.println("Insert or Update data...\n");
fe.saveOrUpdate(session, tx);
//Fetching data...
System.out.println("Fetching data...\n");
fe.getContactRecords(list,session);

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();

}

}
public void saveOrUpdate(Session session,Transaction tx) {
//Create new instance of Contact and set values in it by reading them from form object
System.out.println("Inserting Record");

// TODO Auto-generated method stub
Contact contact = new Contact();
contact.setId(7);
contact.setFirstName("Deepak");
contact.setLastName("Kumar");
contact.setEmail("deepak_38@yahoo.com");
session.saveOrUpdate(contact);
tx.commit();
System.out.println("\n before update");
}
public void getContactRecords(List list,Session session){
Query query = session.createQuery("from roseindia.tutorial.hibernate.Contact");
/** execute query and get result in form of Java objects */
list = query.list();
System.out.println("intial value---> "+list.get(0));
if(list.size() >0){
int i=0;
for(;i<list.size();i++)
{
Contact c = (Contact)list.get(i);

System.out.println(c.getId());
System.out.println(c.getFirstName());
System.out.println(c.getLastName());
System.out.println(c.getEmail());

}
}
}
}

And one more important thing is we need to provide as
In hibernate.cfg.xml:

<property name="hibernate.connection.password">root</property>

After running successfully please check in DB for the row insertion.


Regards
Narendra

Posted by Narendra on Monday, 02.22.10 @ 19:44pm | #95050

The above code failed to insert the date into the table
cause: Client application code does not have begin transaction and the assigment to the transaction interface.

Posted by Narendra on Sunday, 02.21.10 @ 17:06pm | #95005

the solution given by sudhir and others make above example working and complete,,thanks.
Change it as below:

Transaction tx = session.beginTransaction();
Contact contact = new Contact();
contact.setFirstName("Arun");
contact.setLastName("Jain");
contact.setEmail("akj_lh@yahoo.co.in");
session.save(contact);
tx.commit();

Posted by priyanka on Friday, 02.19.10 @ 07:05am | #94941

excellent website for learning

Posted by sindhura on Tuesday, 02.16.10 @ 16:12pm | #94881

Thanks for keeping up with the simplicity on ORM and Hibernate concepts. I was able to understand this concept with in few mins. Good job guys !

Posted by J2EEmarveller on Sunday, 01.10.10 @ 02:47am | #93923

@Deepak and Arun(Your snipplet for transcation management completed this tutorial)

Nice tutorial! worked perfectly!

Posted by karthik on Wednesday, 12.30.09 @ 16:14pm | #93694

Use latest jar: cglib-nodep-2[1].1_3.jar

Posted by Santoshi on Friday, 12.18.09 @ 18:23pm | #93473

Hello,
I am running this example (exactly as is) and the new row is not populated in DB.
I am running the query select(*) from contact and get 0 rows as result.
My console shows the exactly same as yours in runtime.
Please advice.
Many thanks in adavcne,
Boris.

Posted by Boris on Sunday, 12.13.09 @ 13:29pm | #93331

Hi Roland,
same problem here with no errors and no rows.

After I used transactions, i got rows in my db :)

Try this:

...
session =sessionFactory.openSession();


Transaction tr = session.beginTransaction();

Contact contact = new Contact();
...

tr.commit();

I hope this will help, i know that is not best trick.

regards

Posted by moa on Tuesday, 11.17.09 @ 03:28am | #92629

Hy Roland,
try to change the Contact table engine to MyISAM using a MySql
tool like MySqlBrowser with this
command :

ALTER TABLE `hibernatetutorial`.`contact` ENGINE = MyISAM
ROW_FORMAT = DYNAMIC;

Posted by Brainjar on Friday, 11.6.09 @ 16:20pm | #92381

Hi,

I am using the Oracle DB. I am able to execute the program with out any errors. It is also showing the Insert Command as it is shown in the output here. But when i check the CONTACT table in the schema there is no record. Could you please help me out in solving this.

Posted by Sundeep on Wednesday, 10.14.09 @ 23:34pm | #91769

can some one help me to solve this
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: Invalid authorization specification message from server: "Access denied for user 'root'@'localhost' (using password: YES)"
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1997)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1906)
at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:2520)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:817)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:1786)
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 kavya on Friday, 10.9.09 @ 08:45am | #91579

Hi,
For those of u who r getting NullPointerException while creating sessionfactory (SessionFactory sf = new Configuration().configure().buildSessionFactory();) import all required jar files.. View the readme file in lib directory to get the list of required jar files. log4j jar file is also required. Otherwise creating new configuration will fail and it goes to finally block where session object is null and u get NullPointerException.

Posted by Pradeep on Friday, 09.25.09 @ 05:37am | #91187

Hi, I have used JDBCTrancration class insted of Transaction Interface, that worked fine.as JDBCTranction uses Transaction,but when I use Transacton interface it is showing exception.

Posted by vedavyas on Tuesday, 09.22.09 @ 13:22pm | #91111

thanks roseindia this code is workin perfectly.Guys just add Transaction tx = session.beginTransaction(); and tx.commit(); after session.save(), values will be inserted. good luck

Posted by ujwala on Monday, 09.21.09 @ 11:51am | #91080

Nice tutorial sir. But it seems that I can't run the FirstExample properly

Exception in thread "main" org.hibernate.exception.GenericJDBCException:Cannot open connection at org.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:92)
...(other errors)
Caused by: java.sql.SQLException: Unable to connect to any hosts due to exception: java.net.SocketException: java.net.ConnectException: Connection refused

I tried to sniff the transaction through wireshark but no transaction is done between the db and the program.

A little help will be greatly appreciated.

Thanks.


Posted by earl on Wednesday, 09.2.09 @ 14:15pm | #90517

Hi

I get this error when i run this program

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.
Also can anyone tell me how to write code with DB2 or oracle

Posted by R on Friday, 08.28.09 @ 03:55am | #90374

As when we will run this code it will generates errors . As the session was not started in a transaction, plz made correction to this.

Posted by subba on Friday, 08.21.09 @ 17:05pm | #90204

Can I do multiple inserts within same session / transaction?
But it was failed for me.
See the example below :

SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session = sessionFactory.openSession();
org.hibernate.Transaction tx = session.beginTransaction();
Contact contact = new Contact();
contact.setId(1);
contact.setFirstName("Deepak");
contact.setLastName("kumar");
contact.setEmail("deepak_kumar@yahoo.com");
session.save(contact);
Contact contact = new Contact();
contact.setId(2);
contact.setFirstName("Ramesh");
contact.setLastName("Aravind");
contact.setEmail("Ramesh_Aravind@yahoo.com");
session.save(contact);
tx.commit();

Posted by Viswanathan Saravanan on Tuesday, 08.18.09 @ 09:23am | #90092

What you have said I follow all the steps but I am not able to get the output.

Exception is:

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


Is it require to do some setting in MySql.
Please give the solution I given done a lot of googling but didn't get the solution.

Posted by Atul Singh on Sunday, 08.9.09 @ 10:45am | #89880

Thank you very much arun.....
I got my code worked successfully after adding the transaction begin and transaction commit lines.

Thanks.

Posted by BhagyaLakshmi on Wednesday, 08.5.09 @ 17:49pm | #89825

I finaly got the row permanently inserted into the database.

I changed my FirstExample.java code to the following.

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

}

}
}

Posted by Roland Brown on Sunday, 07.12.09 @ 09:17am | #89248

Hello,

I ran the example using MYSQL 5.1 and Intellij 7.5.

After FirstExample.java runs I get the message "Inserting Record
Done
Hibernate: insert into CONTACT (FIRSTNAME, LASTNAME, EMAIL, ID) values (?, ?, ?, ?)". There are no errors. When I then use Aqua Data Studio to look at the contact table it says there are no rows in it. What amd I missing?

Posted by Roland Brown on Friday, 07.10.09 @ 06:18am | #89211

If Data is not Saved in table .
then you must add the
Tranction object

Transaction tx = session.beginTransaction();

Posted by Arun Bhati on Tuesday, 06.30.09 @ 10:44am | #88906

Exception in thread "main" java.lang.NullPointerException
at FirstExample.main(FirstExample.java:34)

Posted by iemre on Monday, 06.22.09 @ 19:21pm | #88710

i follow all above steps, now i m trying to run the application. On console screen it show above output message, but it can't insert any value on my DB tables???

can you please explain why not it insert any value in DB tables ???

Posted by Nitin on Thursday, 05.21.09 @ 10:26am | #87877

which file i need to run as java application?

if i select the project,
then i am facing the below issue:
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

Posted by amit on Thursday, 05.7.09 @ 14:02pm | #87471

-- Copy contact.hbm.xml, and hibernate.cfg.xml in the bin directory of the project using windows explorer.
What is target forder?


-- I download the example and try to run but failed to appear exception following
Exception in thread "main" java.lang.NullPointerException at roseindia.tutorial.hibernate.FirstExample.main(FirstExample.java:36)

Posted by mtlx on Thursday, 03.26.09 @ 02:43am | #86230


what about the data base in this exemple?

Posted by DJAAD on Saturday, 03.14.09 @ 09:12am | #85834

Caused by: java.sql.SQLException: Invalid authorization specification message from server: "Access denied for user 'root'@'localhost' (using password: NO)"

is what am getting.when my username and password are "root"

Posted by kamali on Thursday, 01.29.09 @ 01:23am | #84264

Hallo,

I followed the tutorial, created the sample project in myEclipse, but cannot run FirstExample. It gets an UnsupportedClassVersionError.

Please, advice if possible.

Stacktrace:
ava.lang.UnsupportedClassVersionError: Bad version number in .class file
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)


UnsupportedClassVersionError: Bad version number in .class file

Posted by Yntze Prins on Tuesday, 01.13.09 @ 01:23am | #83768

This is a perfect tutorial.
but as mentioned in the comments add the transaction statement to complete the inserting.

Posted by suresh on Thursday, 01.8.09 @ 00:37am | #83597

When i was runnig the firstExample i hava a problem in NoClassDefFoundError

java.lang.NoClassDefFoundError: roseindia/tutorial/hibernate/FirstExample
Exception in thread "main"

I am add the all jar files
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");
Transaction tx = session.beginTransaction();
Contact contact = new Contact();
contact.setId(1);
contact.setFirstName("Deepak");
contact.setLastName("Kumar");
contact.setEmail("deepak_38@yahoo.com");
session.save(contact);
tx.commit();
System.out.println("Done");

Posted by sudhakar on Wednesday, 12.24.08 @ 23:37pm | #83145

Hibernate source code is very nice.

Posted by Mahes on Tuesday, 12.23.08 @ 15:05pm | #83104

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Inserting Record
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 FirstExample.main(FirstExample.java:35)
Caused by: java.sql.SQLException: Unable to connect to any hosts due to exception: java.net.SocketException: Invalid argument: connect

** BEGIN NESTED EXCEPTION **

java.net.SocketException
MESSAGE: Invalid argument: connect

STACKTRACE:

java.net.SocketException: Invalid argument: 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 FirstExample.main(FirstExample.java:35)


** 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
Done

Posted by sudheer on Monday, 12.22.08 @ 00:43am | #83027

while running this apllication i m getting like editor does't have main type.

Posted by sudheer on Monday, 12.15.08 @ 23:24pm | #82799

Hi (whoever wrote this example),

The code in FirstExample.java is incomplete. It will compile and execute fine but will now insert any records in the DB.

Change it as below:
Transaction tx = session.beginTransaction();
Contact contact = new Contact();
contact.setFirstName("Arun");
contact.setLastName("Jain");
contact.setEmail("akj_lh@yahoo.co.in");
session.save(contact);
tx.commit();


Regards
-Arun

Posted by Arun Jain on Monday, 12.8.08 @ 06:24am | #82509

Perfect tutorial..

Posted by ufuk on Thursday, 12.4.08 @ 14:45pm | #82405

When i was runnig the firstExample i hava a problem in NoClassDefFoundError

Posted by niranjan on Monday, 12.1.08 @ 06:42am | #82236

When the application and got output as shown in tutorial. but it did not insert any record in the database.
The reason is because the database operation need to be enclosed in a transaction and the it should be commited.

Here is the sample code:

SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session = sessionFactory.openSession();
org.hibernate.Transaction tx = session.beginTransaction();
Contact contact = new Contact();
contact.setId(1);
contact.setFirstName("Deepak");
contact.setLastName("kumar");
contact.setEmail("deepak_kumar@yahoo.com");
session.save(contact);
tx.commit();

Hope it will be useful for the some one struggling like me to run the application ;)

Posted by Kalyani on Sunday, 11.30.08 @ 00:53am | #82188

@preeti

Thanks for that list...

However, in order to get this to work, I also needed to add:

slf4j-1.5.6
javassist.jar

Posted by Kessler Brian on Sunday, 11.23.08 @ 15:21pm | #81939

[I'm chanaka

When I Run the sample project it gives following error........]


run-single:
Nov 20, 2008 3:44:29 PM org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.0rc1
Nov 20, 2008 3:44:29 PM org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
Nov 20, 2008 3:44:29 PM org.hibernate.cfg.Environment <clinit>
INFO: using CGLIB reflection optimizer
Nov 20, 2008 3:44:29 PM org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
Nov 20, 2008 3:44:29 PM org.hibernate.cfg.Configuration configure
INFO: configuring from resource: /hibernate.cfg.xml
Nov 20, 2008 3:44:29 PM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: /hibernate.cfg.xml
Nov 20, 2008 3:44:29 PM org.hibernate.cfg.Configuration getConfigurationInputStream
WARNING: /hibernate.cfg.xml not found
/hibernate.cfg.xml not found

Posted by chanaka on Thursday, 11.20.08 @ 05:00am | #81849

hi
client code(main is not correct) bcz you are not begin Transaction and close the Transaction . here find the correct code



package roseindia.tutorial.hibernate;

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


/**
* @author appaji
*
* 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();
Transaction ts=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.setId(81);
contact.setFirstName("first");
contact.setLastName("last");
contact.setEmail("ramojo");

session.save(contact);
ts.commit();
System.out.println("Done");
}catch(HibernateException he) {
System.out.println("hibernate exception occured");
he.printStackTrace();

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

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

}

}
}

Posted by appaji on Tuesday, 11.18.08 @ 06:25am | #81784

Hello everyone,

I am new to Hibernate and trying to execute the FirstExample in this tutorial. I am getting the following message. Not clear on what I missed.

I have added all the below said jars in the classpath of my eclipse project. and also placed both the xml files in the bin directory.

antlr-2.7.6.jar
commons-collections-3.1.jar
commons-logging-1.0.jar
dom4j-1.6.1.jar
javassist-3.4.GA.jar
jta-1.1.jar
mysql-connector-java-3.0.16-ga-bin.jar
mysql-connector-java-3.1.6-bin.jar
slf4j-api-1.5.3.jar
slf4j-jcl-1.5.3.jar
hibernate3.jar

I am still getting the NPE at line 37. I have created the Contact table in the mySQL database as mentioned in the below comments. I installed mySQL and was able to create the table also.

Kindly help me in getting this through.

Thanks & Regards,
HariKrishna

Posted by Harikrishna on Wednesday, 11.12.08 @ 17:37pm | #81620

After sessionfactory.opensession() method, add below line:
Transaction trx = session.beginTransaction();
and
After session.save(contact) method, add below line:
trx.commit();

Posted by Sunaina on Friday, 10.31.08 @ 14:10pm | #81444

Hi,

For those who are not able to insert the row in the database, just try the follwing code and check..

Transaction tc = session.beginTransaction();
session.save(contact);
tc.commit();

In other words, just commit the transaction..
Saw this solution on the Hibernate.org forum..
( http://forum.hibernate.org/viewtopic.php?p=2393098 )..

Posted by V on Thursday, 10.23.08 @ 15:06pm | #81266

I found this error when i try to run the sample application org.hibernate.HibernateException: /hibernate.cfg.xml not found

Posted by sonu on Thursday, 10.23.08 @ 13:52pm | #81263

data not inserting after ececution of program i get Hibernate: insert into CONTACT (FIRSTNAME, LASTNAME, EMAIL, ID) values (?, ?, ?, ?) message but no data found in contact table please help

Posted by shabarish on Wednesday, 10.22.08 @ 09:55am | #81229

hi ,
data not inserting into table created the table as :
CREATE TABLE `contact` (
`ID` int(11) NOT NULL,
`FIRSTNAME` varchar(50) default NULL,
`LASTNAME` varchar(50) default NULL,
`EMAIL` varchar(50) default NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
but no data getting inserted into db but program is executed fine

Posted by shabarish on Wednesday, 10.22.08 @ 09:34am | #81228

data not inserting into database but progrm is executed successfully

Posted by Shabarish on Wednesday, 10.22.08 @ 09:25am | #81227

hi

At first you will have to change your hibernate.cfg.xml to indicate which username and password and port will be used to establish the connection.

Then you can create a database named hibernatetutorial (the hibernate won´t do it for you in this case)

Then you have to create a table named contact whose id column is auto increment. The fucking hibernate does not create the database as mentioned above and in adittion it creates a table contact without auto increment ID) If you let hibernate create the table your app will run fine but will not insert any record into table.

Here is the create statement
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 CHARLLES CUBA on Friday, 10.17.08 @ 22:25pm | #81150

hi

At first you will have to change your hibernate.cfg.xml to indicate which username and password and port will be used to establish the connection.

Then you can create a database named hibernatetutorial (the hibernate won´t do it for you in this case)

Then you have to create a table named contact whose id column is auto increment. The fucking hibernate does not create the database as mentioned above and in adittion it creates a table contact without auto increment ID) If you let hibernate create the table your app will run fine but will not insert any record into table.

Here is the create statement
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 CHARLLES CUBA on Friday, 10.17.08 @ 22:24pm | #81149

I bumped into the same problem as you did.

Posted by charlles cuba on Friday, 10.17.08 @ 22:05pm | #81148

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 a 'commit' issue .Add the below line to hibernate.cfg.xml.

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


Posted by Saravanarajan on Thursday, 08.28.08 @ 20:00pm | #75721

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

hi,

if row in not inserted try following:

Transaction tx = session.beginTransaction();
....
.
...
tx.commit();

Posted by selvaraj on Wednesday, 07.9.08 @ 19:10pm | #66462

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

Exception in thread "main" java.lang.ExceptionInInitializerError
at roseindia.tutorial.hibernate.FirstExample.main(FirstExample.java:16)
Caused by: org.apache.commons.logging.LogConfigurationException: org.apache.commons.logging.LogConfigurationException: java.lang.NullPointerException (Caused by java.lang.NullPointerException) (Caused by org.apache.commons.logging.LogConfigurationException: java.lang.NullPointerException (Caused by java.lang.NullPointerException))
at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:543)
at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:235)
at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:209)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:351)
at net.sf.hibernate.cfg.Configuration.<clinit>(Configuration.java:95)
... 1 more
Caused by: org.apache.commons.logging.LogConfigurationException: java.lang.NullPointerException (Caused by java.lang.NullPointerException)
at org.apache.commons.logging.impl.LogFactoryImpl.getLogConstructor(LogFactoryImpl.java:397)
at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:529)
... 5 more
Caused by: java.lang.NullPointerException
at org.apache.commons.logging.impl.LogFactoryImpl.getLogConstructor(LogFactoryImpl.java:374)
... 6 more

Posted by Balamurugan on Wednesday, 06.4.08 @ 15:22pm | #62072

I followed the tutorial but can not run the example. I got the following exception when running the sample code:
Exception in thread "main" java.lang.NullPointerException
at roseindia.tutor.hibernate.FirstExample.main(FirstExample.java:39)

I tried to degub, and find out that after the below line (create a new SessionFactory object):
SessionFactory sf = new Configuration().configure().buildSessionFactory();
the programm went to session.flush() at the finally block.

Could you please tell me why? Thanks.

Posted by Lam on Tuesday, 05.13.08 @ 10:08am | #59660

how to create web page using Hibernate

Posted by prasad on Thursday, 05.8.08 @ 13:36pm | #58898

I got this when i tried to run it......
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)
........

not sure why though... i followed the tutorial perfectly...

Posted by B on Tuesday, 04.29.08 @ 07:27am | #58095

I am new to this hibernate/eclipse thing, but my goodness! this is so wonderful. Good work guys.

Posted by David on Wednesday, 03.26.08 @ 15:32pm | #54389

Ask programming questions?

 

 

Back to Tutorial

 

  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name

 

 
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

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

Copyright © 2007. All rights reserved.