after running the firstexample program it runs successfully but doesn't insert the hardcoded values into the contact table. please explain me why values are not inserted into the contact table?
I followed this tutorial and session.flush didnt work for me.
I googled this issue and still couldnt find any promising results.
The solution Ive discovered so far is transaction.commit.
Any bright ideas?
Hi I am learning how to use hibernate and I tried this example, but I have an error in this line: session.flush();
Can you please show please, how the project tree is organized.
When I run above example I have with session.flush(). Error message:
exception
java.lang.NullPointerException
helloPackage.hello.doPost(hello.java:80)
javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722) . Here line 80 means: session.flush();. please reply why ???
I got the message
Hibernate: insert into CONTACT (FIRSTNAME, LASTNAME, EMAIL, ID) values (?, ?, ?, ?)
And the values are not inserting??
Please help..
Code ProblemAbhishek Chaudhary February 2, 2012 at 5:32 PM
I am new in hibernate, I am using your this example as reference. But your this example is not working, The program is not giving any output, can you tell me why is it so??
You face error in bean file,your data can not pass to database so use this bean file(Problem is in only bean file)
<!-- file is here -->
public class FirstExample extends Contact{
public static void main(String[] args) {
Session session = null;
Transaction transaction = null ;
try{
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session =sessionFactory.openSession();
transaction = session.beginTransaction();
transaction.begin();
//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(7);
contact.setFirstName("Deepak");
contact.setLastName("Kumar");
contact.setEmail("deepak_38@yahoo.com");
session.save(contact);
System.out.println("Done");
transaction.commit();
session.flush();
session.close();
}
catch(Exception e){
System.out.println("error in first"+e.getMessage());
}
}
}
Hi,
If i use <generator class="assigned"/> in the mapping file for MYSQL database its not saving data.
Instead of that i have used <generator class="native"/> which is working fine after that.
This code is incomplete.
To complete this code create an object of transaction class.
And use commit() method.
ie
Transaction tr=session.beginTransaction();
tr.commit();
Running FirstExample will not insert record since transaction is not saved. The code has to be like this
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(6);
contact.setFirstName("Deepak");
contact.setLastName("Kumar");
contact.setEmail("deepak_38@yahoo.com");
session.beginTransaction();
session.save(contact);
tx.commit();
hi, i copy/paste this codes on netbeans7.2 and after build and deploy i see this messages in run (DB is: mysql5.2):
run:
Aug 23, 2012 10:36:11 AM org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.2.5
Aug 23, 2012 10:36:11 AM org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
Aug 23, 2012 10:36:11 AM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : cglib
Aug 23, 2012 10:36:11 AM org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
Aug 23, 2012 10:36:11 AM org.hibernate.cfg.Configuration configure
INFO: configuring from resource: /hibernate.cfg.xml
Aug 23, 2012 10:36:11 AM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: /hibernate.cfg.xml
Aug 23, 2012 10:36:11 AM org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : contact.hbm.xml
Aug 23, 2012 10:36:12 AM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: roseindia.tutorial.hibernate.Contact -> CONTACT
Aug 23, 2012 10:36:12 AM org.hibernate.cfg.Configuration doConfigure
INFO: Configured SessionFactory: null
Aug 23, 2012 10:36:12 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
Aug 23, 2012 10:36:12 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 10
Aug 23, 2012 10:36:12 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: autocommit mode: false
Aug 23, 2012 10:36:12 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost/hibernatetutorial
Aug 23, 2012 10:36:12 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=root, password=****}
Aug 23, 2012 10:36:12 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: RDBMS: MySQL, version: 5.5.20
Aug 23, 2012 10:36:12 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-5.1.18 ( Revision: tonci.grgin@oracle.com-20110930151701-jfj14ddfq48ifkfq )
Aug 23, 2012 10:36:12 AM org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.MySQLDialect
Aug 23, 2012 10:36:12 AM org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Using default transaction strategy (direct JDBC transactions)
Aug 23, 2012 10:36:12 AM org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
Aug 23, 2012 10:36:12 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
Aug 23, 2012 10:36:12 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
Aug 23, 2012 10:36:12 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch size: 15
Aug 23, 2012 10:36:12 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch updates for versioned data: disabled
Aug 23, 2012 10:36:12 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: enabled
Aug 23, 2012 10:36:12 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): enabled
Aug 23, 2012 10:36:12 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Connection release mode: auto
Aug 23, 2012 10:36:12 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Maximum outer join fetch depth: 2
Aug 23, 2012 10:36:12 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
Aug 23, 2012 10:36:12 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: disabled
Aug 23, 2012 10:36:12 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: disabled
Aug 23, 2012 10:36:12 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL inserts for batching: disabled
Aug 23, 2012 10:36:12 AM org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
Aug 23, 2012 10:36:12 AM org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
INFO: Using ASTQueryTranslatorFactory
Aug 23, 2012 10:36:12 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
Aug 23, 2012 10:36:12 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JPA-QL strict compliance: disabled
Aug 23, 2012 10:36:12 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
Aug 23, 2012 10:36:12 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
Aug 23, 2012 10:36:12 AM org.hibernate.cfg.SettingsFactory createCacheProvider
INFO: Cache provider: org.hibernate.cache.NoCacheProvider
Aug 23, 2012 10:36:12 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
Aug 23, 2012 10:36:12 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: disabled
Aug 23, 2012 10:36:12 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Echoing all SQL to stdout
Aug 23, 2012 10:36:12 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: disabled
Aug 23, 2012 10:36:12 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
Aug 23, 2012 10:36:12 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
Aug 23, 2012 10:36:12 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Named query checking : enabled
Aug 23, 2012 10:36:12 AM org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
Aug 23, 2012 10:36:13 AM org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
Aug 23, 2012 10:36:13 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: Running hbm2ddl schema update
Aug 23, 2012 10:36:13 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: fetching database metadata
Aug 23, 2012 10:36:13 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: updating schema
Aug 23, 2012 10:36:13 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: table found: hibernatetutorial.contact
Aug 23, 2012 10:36:13 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: columns: [id, email, lastname, firstname]
Aug 23, 2012 10:36:13 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: foreign keys: []
Aug 23, 2012 10:36:13 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: indexes: [primary]
Aug 23, 2012 10:36:13 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: schema update complete
Inserting Record
Done
Hibernate: insert into CONTACT (FIRSTNAME, LASTNAME, EMAIL, ID) values (?, ?, ?, ?)
querykarunakar sarabu September 5, 2012 at 10:23 AM
please tell me how to test this application. i cant find it in the online tutorial.
Please put this lines in code.
import org.hibernate.Transaction;
.
.
.
Transaction tx=session.beginTransaction(); // Add this soon after initializing session object
tx.commit() // just before saving the session
I cant get the output by using above code.I am getting the error
Could not parse mapping document from resource contact.hbm.xml
Exception in thread "main" java.lang.NullPointerException
at roseindia.FirstExample.main(FirstExample.java:34)
Hi There,
No doubt, your this tutorial (http://www.roseindia.net/hibernate/firstexample.shtml) is very good and informative. But when I tried to use above example as it is, It was not working. I would like to give you my updated code, You can review this and if find this relevant than please update this example.
1.) Need to create object of transaction class as below after session creation.
org.hibernate.Transaction txn = session.beginTransaction();
txn.begin();
2.) Need to commit transaction after save command as:
session.save(<NAME_OF_OBJECT>);
txn.commit();
i tried your program.its giving me the 'hibernate.cfg.xml' file not found error.while debugging, i noticed that the code after SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
is not being executed.
pls help
Hey,
Nice and simple article
I tried your example.It works good but FirstExample.java fails to insert to database.I am using SqlServer 2005
<property name ="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name ="hibernate.connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
From the logs I can see that the INSERT statement is getting created fine and no exceptions are present but still no entry in database,any ideas?
Total example is correct but data is not going to be inserted bcoz of, Not opening Transaction. i.e.., After
session =sessionFactory.openSession(); INSERT
Transaction t =session.beginTransaction();
and at last say
t.commit();
Then ur data will be inserted into the database.
values are not inserted into the table?anonymous April 9, 2011 at 6:00 PM
after running the firstexample program it runs successfully but doesn't insert the hardcoded values into the contact table. please explain me why values are not inserted into the contact table?
comment on ur exampleshrikant kamble June 7, 2011 at 7:34 PM
this very good for beginer
good!sid June 16, 2011 at 4:48 PM
good helpfull!
Regarding xml filespriya July 10, 2011 at 5:27 PM
Hello sir, Do we have to put all the xml files in the src folder only?
hai shabbir July 1, 2011 at 4:04 PM
ya friends ur giving full information about how to write first hibernet program but how to run ? information is not there.
Hibernate Basicsprasad September 21, 2011 at 8:22 PM
If we have Servlet-Jsp technologies then why we use hibernate instead of it
session.flush not working!doesn't matter October 12, 2011 at 4:11 PM
I followed this tutorial and session.flush didnt work for me. I googled this issue and still couldnt find any promising results. The solution Ive discovered so far is transaction.commit. Any bright ideas?
ErrorBilaal December 6, 2011 at 12:00 AM
Hi I am learning how to use hibernate and I tried this example, but I have an error in this line: session.flush(); Can you please show please, how the project tree is organized.
Problem with this exampleBhoj Raj bhatt December 17, 2011 at 8:52 AM
When I run above example I have with session.flush(). Error message: exception java.lang.NullPointerException helloPackage.hello.doPost(hello.java:80) javax.servlet.http.HttpServlet.service(HttpServlet.java:641) javax.servlet.http.HttpServlet.service(HttpServlet.java:722) . Here line 80 means: session.flush();. please reply why ???
No InsertionGaurav January 3, 2012 at 3:12 AM
I got the message Hibernate: insert into CONTACT (FIRSTNAME, LASTNAME, EMAIL, ID) values (?, ?, ?, ?) And the values are not inserting?? Please help..
Code ProblemAbhishek Chaudhary February 2, 2012 at 5:32 PM
I am new in hibernate, I am using your this example as reference. But your this example is not working, The program is not giving any output, can you tell me why is it so??
himani February 14, 2012 at 7:02 PM
good site
Required Jars & MySqlDriverchartahir February 17, 2012 at 10:57 PM
Hi, Can you also add here about which jars are required to make this code work and how/where to get the MySQL Driver.
Error Solvedjubinpatel March 1, 2012 at 12:36 PM
You face error in bean file,your data can not pass to database so use this bean file(Problem is in only bean file) <!-- file is here --> public class FirstExample extends Contact{ public static void main(String[] args) { Session session = null; Transaction transaction = null ; try{ SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(); session =sessionFactory.openSession(); transaction = session.beginTransaction(); transaction.begin(); //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(7); contact.setFirstName("Deepak"); contact.setLastName("Kumar"); contact.setEmail("deepak_38@yahoo.com"); session.save(contact); System.out.println("Done"); transaction.commit(); session.flush(); session.close(); } catch(Exception e){ System.out.println("error in first"+e.getMessage()); } } }
Error : No Reflection in database Darshil March 30, 2012 at 7:34 PM
Hey friends use Transaction ta=session.beginTransaction; //after session.save(); ta.commit();
Error while running this programPavan April 25, 2012 at 5:20 PM
Hi, If i use <generator class="assigned"/> in the mapping file for MYSQL database its not saving data. Instead of that i have used <generator class="native"/> which is working fine after that.
Error while running this programPavan April 25, 2012 at 5:47 PM
If dont commit the session the values are not getting stored in the database.
hibernateSANJEEV RANJAN May 4, 2012 at 1:06 PM
thank you, now i'm albe to write the hibernate file.
bug in Writing First Hibernate Codearun kumar May 15, 2012 at 5:31 PM
In this program we are not using transaction objection to commit the data..
all links to same pagekumar rajput May 29, 2012 at 5:29 PM
why have you provided previous index and next links when they point to same web page !!
software enegineerZhongmingLiu June 1, 2012 at 7:21 AM
like it and do it
errorchaitya June 9, 2012 at 2:47 PM
you need transcation object to commit the data
outdatedeiso June 15, 2012 at 3:28 PM
model
hibernateharsha rao July 14, 2012 at 9:31 PM
nice
Incomplete codeChitranshu July 25, 2012 at 12:47 PM
This code is incomplete. To complete this code create an object of transaction class. And use commit() method. ie Transaction tr=session.beginTransaction(); tr.commit();
save transactionRajesh Kumar August 18, 2012 at 1:21 AM
Running FirstExample will not insert record since transaction is not saved. The code has to be like this 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(6); contact.setFirstName("Deepak"); contact.setLastName("Kumar"); contact.setEmail("deepak_38@yahoo.com"); session.beginTransaction(); session.save(contact); tx.commit();
failmaktoom August 23, 2012 at 11:39 AM
hi, i copy/paste this codes on netbeans7.2 and after build and deploy i see this messages in run (DB is: mysql5.2): run: Aug 23, 2012 10:36:11 AM org.hibernate.cfg.Environment <clinit> INFO: Hibernate 3.2.5 Aug 23, 2012 10:36:11 AM org.hibernate.cfg.Environment <clinit> INFO: hibernate.properties not found Aug 23, 2012 10:36:11 AM org.hibernate.cfg.Environment buildBytecodeProvider INFO: Bytecode provider name : cglib Aug 23, 2012 10:36:11 AM org.hibernate.cfg.Environment <clinit> INFO: using JDK 1.4 java.sql.Timestamp handling Aug 23, 2012 10:36:11 AM org.hibernate.cfg.Configuration configure INFO: configuring from resource: /hibernate.cfg.xml Aug 23, 2012 10:36:11 AM org.hibernate.cfg.Configuration getConfigurationInputStream INFO: Configuration resource: /hibernate.cfg.xml Aug 23, 2012 10:36:11 AM org.hibernate.cfg.Configuration addResource INFO: Reading mappings from resource : contact.hbm.xml Aug 23, 2012 10:36:12 AM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues INFO: Mapping class: roseindia.tutorial.hibernate.Contact -> CONTACT Aug 23, 2012 10:36:12 AM org.hibernate.cfg.Configuration doConfigure INFO: Configured SessionFactory: null Aug 23, 2012 10:36:12 AM org.hibernate.connection.DriverManagerConnectionProvider configure INFO: Using Hibernate built-in connection pool (not for production use!) Aug 23, 2012 10:36:12 AM org.hibernate.connection.DriverManagerConnectionProvider configure INFO: Hibernate connection pool size: 10 Aug 23, 2012 10:36:12 AM org.hibernate.connection.DriverManagerConnectionProvider configure INFO: autocommit mode: false Aug 23, 2012 10:36:12 AM org.hibernate.connection.DriverManagerConnectionProvider configure INFO: using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost/hibernatetutorial Aug 23, 2012 10:36:12 AM org.hibernate.connection.DriverManagerConnectionProvider configure INFO: connection properties: {user=root, password=****} Aug 23, 2012 10:36:12 AM org.hibernate.cfg.SettingsFactory buildSettings INFO: RDBMS: MySQL, version: 5.5.20 Aug 23, 2012 10:36:12 AM org.hibernate.cfg.SettingsFactory buildSettings INFO: JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-5.1.18 ( Revision: tonci.grgin@oracle.com-20110930151701-jfj14ddfq48ifkfq ) Aug 23, 2012 10:36:12 AM org.hibernate.dialect.Dialect <init> INFO: Using dialect: org.hibernate.dialect.MySQLDialect Aug 23, 2012 10:36:12 AM org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory INFO: Using default transaction strategy (direct JDBC transactions) Aug 23, 2012 10:36:12 AM org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended) Aug 23, 2012 10:36:12 AM org.hibernate.cfg.SettingsFactory buildSettings INFO: Automatic flush during beforeCompletion(): disabled Aug 23, 2012 10:36:12 AM org.hibernate.cfg.SettingsFactory buildSettings INFO: Automatic session close at end of transaction: disabled Aug 23, 2012 10:36:12 AM org.hibernate.cfg.SettingsFactory buildSettings INFO: JDBC batch size: 15 Aug 23, 2012 10:36:12 AM org.hibernate.cfg.SettingsFactory buildSettings INFO: JDBC batch updates for versioned data: disabled Aug 23, 2012 10:36:12 AM org.hibernate.cfg.SettingsFactory buildSettings INFO: Scrollable result sets: enabled Aug 23, 2012 10:36:12 AM org.hibernate.cfg.SettingsFactory buildSettings INFO: JDBC3 getGeneratedKeys(): enabled Aug 23, 2012 10:36:12 AM org.hibernate.cfg.SettingsFactory buildSettings INFO: Connection release mode: auto Aug 23, 2012 10:36:12 AM org.hibernate.cfg.SettingsFactory buildSettings INFO: Maximum outer join fetch depth: 2 Aug 23, 2012 10:36:12 AM org.hibernate.cfg.SettingsFactory buildSettings INFO: Default batch fetch size: 1 Aug 23, 2012 10:36:12 AM org.hibernate.cfg.SettingsFactory buildSettings INFO: Generate SQL with comments: disabled Aug 23, 2012 10:36:12 AM org.hibernate.cfg.SettingsFactory buildSettings INFO: Order SQL updates by primary key: disabled Aug 23, 2012 10:36:12 AM org.hibernate.cfg.SettingsFactory buildSettings INFO: Order SQL inserts for batching: disabled Aug 23, 2012 10:36:12 AM org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory Aug 23, 2012 10:36:12 AM org.hibernate.hql.ast.ASTQueryTranslatorFactory <init> INFO: Using ASTQueryTranslatorFactory Aug 23, 2012 10:36:12 AM org.hibernate.cfg.SettingsFactory buildSettings INFO: Query language substitutions: {} Aug 23, 2012 10:36:12 AM org.hibernate.cfg.SettingsFactory buildSettings INFO: JPA-QL strict compliance: disabled Aug 23, 2012 10:36:12 AM org.hibernate.cfg.SettingsFactory buildSettings INFO: Second-level cache: enabled Aug 23, 2012 10:36:12 AM org.hibernate.cfg.SettingsFactory buildSettings INFO: Query cache: disabled Aug 23, 2012 10:36:12 AM org.hibernate.cfg.SettingsFactory createCacheProvider INFO: Cache provider: org.hibernate.cache.NoCacheProvider Aug 23, 2012 10:36:12 AM org.hibernate.cfg.SettingsFactory buildSettings INFO: Optimize cache for minimal puts: disabled Aug 23, 2012 10:36:12 AM org.hibernate.cfg.SettingsFactory buildSettings INFO: Structured second-level cache entries: disabled Aug 23, 2012 10:36:12 AM org.hibernate.cfg.SettingsFactory buildSettings INFO: Echoing all SQL to stdout Aug 23, 2012 10:36:12 AM org.hibernate.cfg.SettingsFactory buildSettings INFO: Statistics: disabled Aug 23, 2012 10:36:12 AM org.hibernate.cfg.SettingsFactory buildSettings INFO: Deleted entity synthetic identifier rollback: disabled Aug 23, 2012 10:36:12 AM org.hibernate.cfg.SettingsFactory buildSettings INFO: Default entity-mode: pojo Aug 23, 2012 10:36:12 AM org.hibernate.cfg.SettingsFactory buildSettings INFO: Named query checking : enabled Aug 23, 2012 10:36:12 AM org.hibernate.impl.SessionFactoryImpl <init> INFO: building session factory Aug 23, 2012 10:36:13 AM org.hibernate.impl.SessionFactoryObjectFactory addInstance INFO: Not binding factory to JNDI, no JNDI name configured Aug 23, 2012 10:36:13 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute INFO: Running hbm2ddl schema update Aug 23, 2012 10:36:13 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute INFO: fetching database metadata Aug 23, 2012 10:36:13 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute INFO: updating schema Aug 23, 2012 10:36:13 AM org.hibernate.tool.hbm2ddl.TableMetadata <init> INFO: table found: hibernatetutorial.contact Aug 23, 2012 10:36:13 AM org.hibernate.tool.hbm2ddl.TableMetadata <init> INFO: columns: [id, email, lastname, firstname] Aug 23, 2012 10:36:13 AM org.hibernate.tool.hbm2ddl.TableMetadata <init> INFO: foreign keys: [] Aug 23, 2012 10:36:13 AM org.hibernate.tool.hbm2ddl.TableMetadata <init> INFO: indexes: [primary] Aug 23, 2012 10:36:13 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute INFO: schema update complete Inserting Record Done Hibernate: insert into CONTACT (FIRSTNAME, LASTNAME, EMAIL, ID) values (?, ?, ?, ?)
querykarunakar sarabu September 5, 2012 at 10:23 AM
please tell me how to test this application. i cant find it in the online tutorial.
no commentno comment October 3, 2012 at 3:46 PM
no comment
About Updation of codeamit October 29, 2012 at 11:09 PM
Please put this lines in code. import org.hibernate.Transaction; . . . Transaction tx=session.beginTransaction(); // Add this soon after initializing session object tx.commit() // just before saving the session
errorReem November 17, 2012 at 10:46 PM
when i run the code a java exception has occured any advice thanks
The code is amaizing dibya jyoti das November 19, 2012 at 7:07 PM
This tutorial is very simple as well asa very effective.
Please answersahad November 28, 2012 at 3:54 PM
I cant get the output by using above code.I am getting the error Could not parse mapping document from resource contact.hbm.xml Exception in thread "main" java.lang.NullPointerException at roseindia.FirstExample.main(FirstExample.java:34)
Need to make small correction in the given exampleBhajan January 4, 2013 at 4:37 PM
Hi There, No doubt, your this tutorial (http://www.roseindia.net/hibernate/firstexample.shtml) is very good and informative. But when I tried to use above example as it is, It was not working. I would like to give you my updated code, You can review this and if find this relevant than please update this example. 1.) Need to create object of transaction class as below after session creation. org.hibernate.Transaction txn = session.beginTransaction(); txn.begin(); 2.) Need to commit transaction after save command as: session.save(<NAME_OF_OBJECT>); txn.commit();
unable to run the codevidushe April 3, 2013 at 11:17 AM
i tried your program.its giving me the 'hibernate.cfg.xml' file not found error.while debugging, i noticed that the code after SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(); is not being executed. pls help
small issue with sample codejoseph April 13, 2013 at 6:07 PM
Hey, Nice and simple article I tried your example.It works good but FirstExample.java fails to insert to database.I am using SqlServer 2005 <property name ="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property> <property name ="hibernate.connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property> From the logs I can see that the INSERT statement is getting created fine and no exceptions are present but still no entry in database,any ideas?
Data is not going to be inserted in this example Dilip Voruganti April 28, 2013 at 8:45 PM
Total example is correct but data is not going to be inserted bcoz of, Not opening Transaction. i.e.., After session =sessionFactory.openSession(); INSERT Transaction t =session.beginTransaction(); and at last say t.commit(); Then ur data will be inserted into the database.
Post your Comment