| 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
|
|
||||||||||||||||||||||||||||||
|
Home | JSP | EJB | JDBC | Java Servlets | WAP | Free JSP Hosting | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs |
||||||||||||||||||||||||||||||
Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.
Copyright © 2007. All rights reserved.
Current Comments
22 comments so far (post your own) View All Comments Latest 10 Comments: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
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
Hi Carl,
You get the following exceptions when you do not have the mysql-connector-java-3.0.16-ga-bin.jar and mysql-connector-java-3.1.6-bin.jar in the Java build path
------------------
Exception in thread "main" java.lang.NullPointerException
at roseindia.tutorial.hibernate.FirstExample.main(FirstExample.java:36)
--------------
If you are using eclipse, then Project -> properties - > java Build Path -> libraries tab -> ensure you have MySQL connectors mentioned above here...if not add using the 'Add jars' or 'Add External Jars' option
Posted by saikrishna on Wednesday, 10.15.08 @ 13:56pm | #81095
Thanks to Rose India, and thanks to Deepak, for implementing Hibernate, in such a simple fashion. This program has really worked for me. And helped me to enhance it, for complex application. Thanks again.
If any of you, get problem in inserting data in to contact table.
Create contact table in the following way.
CREATE TABLE `Contact` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
`firstName` VARCHAR( 50 ) NOT NULL ,
`lastName` VARCHAR( 250 ) NOT NULL ,
`email` VARCHAR( 100 ) NOT NULL ,
PRIMARY KEY ( `id` )
) TYPE = MYISAM ;
Posted by Pratap on Thursday, 10.9.08 @ 16:05pm | #80980
You have to create the table for contact for this to work
CREATE TABLE `Contact` (
`id` int(11) NOT NULL default '0',
`firstname` varchar(20) NOT NULL default '',
`lastname` varchar(20) NOT NULL default '',
`email` varchar(30) default NULL,
PRIMARY KEY (`id`)
) TYPE=MyISAM;
Posted by Amro on Wednesday, 09.17.08 @ 18:10pm | #80100
If you are getting nullpointer then there is problem like include all the jar files which are need for hibernate then it will work fine
required jar files for hibernate are:
hibernate3.jar
dom4j.jar
commons-logging.jar
commons-collections.jar
cglib.jar
concurrent.jar
derby-10.1.2.1.jar
jta1.0.1.jar
Posted by preeti on Monday, 09.15.08 @ 17:15pm | #79588
Reply to the questions asked in the forum(after the question).Make the tutorial as small as possible. I downloaded the tutorial and I am able to see many unwanted things which are not required to run a simple program(it may confuse). I too had the same problem which a user has already asked. If you would have answered to his question means i might not have asked the same question. My problem is
(I ran the application and got output as shown in tutorial. but it did not insert any record in database.)
Posted by thiagarajan on Saturday, 09.13.08 @ 14:12pm | #79102
For some reason, my application didn't insert any data into the table. What's wrong?
Posted by handreach on Sunday, 09.7.08 @ 04:06am | #77610
I am getting the following error when I try to run the FirstExample.java in eclipse.
Exception in thread "main" java.lang.NullPointerException
at roseindia.tutorial.hibernate.FirstExample.main(FirstExample.java:36)
Does anyone has a fix for this?
Posted by Carl on Wednesday, 09.3.08 @ 23:38pm | #77021
its really working ... good job..guys..
Posted by shyam on Friday, 08.15.08 @ 11:33am | #72930
while implementing first hibernate code i am getting NullPointerException in main.
Posted by Tejashree D. Bhanawala on Thursday, 08.14.08 @ 16:32pm | #72820
I ran the application and got output as shown in tutorial. but it did not insert any record in database.
I am using oracle 10g and my setting is
<property name="dialect">org.hibernate.dialect.OracleDialect</property>
is it wrong ?
Posted by sandeep on Wednesday, 06.4.08 @ 16:18pm | #62081
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