Home Tutorialhelp Comment Solution is here..complete code of FirstExample

 
 

Comment

Narendra
Solution is here..complete code of FirstExample,
February 22, 2010 at 7:44 PM

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
View All Comments | View Tutorial
Advertisement
Related Tutorial and Articles
Hibernate Questions

hibernate firstexample - Hibernate
hibernate firstexample  Hi all. i m new with hibernate,when i m trying to run my first application i m getting following exception. Error reading resource: Employee.hbm.xml give me the solution. Thank you 

Hibernate Questions

hibernate firstExample not inserting data - Hibernate
in the firstExample as below. I will later post the actual code issue later. here i am...hibernate firstExample not inserting data  hello all , i followed....  Hi friend, Please send me code and explain in detail. Visit 

Hibernate Questions

Hibernate code - Hibernate
Hibernate code  firstExample code that you have given for hibernate... inserted in the database from this file. http://www.roseindia.net/hibernate/runninge-xample.shtml Thanks 

Hibernate Questions

Problem in running first hibernate program.... - Hibernate
/FirstExample Exception in thread "main" " http://www.roseindia.net/hibernate/runninge...Problem in running first hibernate program....  Hi...I am using... programs.It worked fine.To run a hibernate sample program,I followed the tutorial below 

Hibernate-Tutorials

Hibernate 4 AnnotationSessionFactoryBean
caching. Here is the complete code of using the LocalSessionFactoryBean instead... from Hibernate 3 to Hibernate 4. If you use the following code in your Hibernate 4...How to use AnnotationSessionFactoryBean in Hibernate 4? Can it be used 

XML Questions

Can find a solution or code for this - XML
Can find a solution or code for this   Develop a java based tool which can be used to build a GUI structure based on the configurations given in the tool. Input XML Folders/Files E.g:Folder for Main Panel Files for required 

Hibernate Questions

hibernate - Hibernate
hibernate  what is hibernate and how to make a pc hibernating?  Hi friend, Hibernate is based on object oriented concept like java... ,resultset every time. It uses ORM which is a better solution. In Jdbc we use 

Hibernate Questions

hibernate
hibernate  how to impot mysql database client jar file into eclipse for hibernate configuration   Hi Friend, Please visit the following link: http://www.roseindia.net/hibernate/runninge-xample.shtml Thanks 

Hibernate Questions

Hibernate - Hibernate
for me to provide you the solution if problem is clear. please post all code...Hibernate  Hai this is jagadhish while running a Hibernate application i got the exception like this what is the solution for this plz inform me 

Java Beginners

solution
solution   A developer wants you to develop a simple take away restaurant order service. The system reads from a file containing information about the restaurant (such as the name, place and menu). The system then allows the user 

Java Beginners

solution
solution   A developer wants you to develop a simple take away restaurant order service. The system reads from a file containing information about the restaurant (such as the name, place and menu). The system then allows the user 

Java Interview Questions

Please find me a solution that
Please find me a solution that   Write a java program that calculates the area of rectangular, square, triangular, and circle. Your program... the program.   The given code calculates the area of square, rectangle 

Java Beginners

Hibernate code
Hibernate code  programm 4 hibernate  Hi, Read hibernate tutorial at http://www.roseindia.net/hibernate/ Thanks   please read at the the link http://www.roseindia.net/hibernate 

Hibernate Questions

hibernate code - Hibernate
hibernate code  while generating the hibernate code i got the error like org.hibernate.MappingException 

Hibernate Questions

Hibernate Code - Hibernate
Hibernate Code   How to Invoke Stored Procedure in Hibernate???????? Plz provide details code 

Hibernate Questions

Hibernate code problem - Hibernate
Hibernate code problem  how to write hibernate Left outer join program 

JSP Servlet Questions

jsp solution - JSP-Servlet
. Try the following code: 1)ajaxExample.jsp: var xmlhttp function 

Hibernate Questions

hibernate code - Hibernate
hibernate code  How to store a image in mysql or oracle db using struts &hibernate 

Hibernate Questions

HIBERNATE CODE - Hibernate
HIBERNATE CODE  Dear sir, I am working with MyEclipse IDE.I want to connect with MYSQL using Hibernate. What is the Driver Template and URL of MYSQL toconnect using Hibernate 

Hibernate Questions

Hibernate code - Hibernate
Hibernate code  can you show the insert example of Hibernate other than session.save(obj);  Hi I am sending a link where u can find lots of example related to hibernate... http://www.roseindia.net/hibernate 

Hibernate Questions

Hibernate code - Hibernate
Hibernate code   I am facing a problem in hibernate program. Error is ::: Error in reading contact.hbm.xml contact.hbm.xml is my hibernate mapping file.  Hi Friend, check whether you have specified correct path 

Hibernate Questions

Hibernate code - Hibernate
Hibernate code   how to write hql query for retriveing data from multiple tables 

Hibernate Questions

Hibernate code problem - Hibernate
Hibernate code problem   Hi This is Raju I tried the first example of hibernate course material.This is to insert a record into CONTACT table.Is Hibernate code automatically creates the CONTACT table and then insert 

Hibernate Questions

Hibernate code - Hibernate
Hibernate code   example code of how insert data in the parent table and child tabel coloums at a time in hibernate  Hi friend, I am...: http://www.roseindia.net/hibernate/insert-data-database.shtml Thanks 

Hibernate Questions

Hibernate code problem - Hibernate
Hibernate code problem  Hi, This is Birendra Pradhan.I want... in the DAO.Can it be possibe. Please send some sample code.. thanks... to : http://www.roseindia.net/hibernate/index.shtml Thanks 

Hibernate Questions

Struts-Hibernate-Integration - Hibernate
Struts-Hibernate-Integration  Hi, I was executing struts hibernate intgeration code the following error has occured. Anyone can give me the solution for folllowing issues javax.servlet.ServletException 

Hibernate Questions

Hibernate code - Hibernate
Hibernate code   Hi How to intract struts , spring and Hibernet. Explain architecture flow.   Hi Friend, Please visit the following link: http://www.roseindia.net/struts/hibernate-spring/index.shtml Here 

Hibernate Questions

Hibernate code problem - Hibernate
Hibernate code problem  Hi This is Raju.I tried the first example of Hibernate material what u have given. I have written contact.java... session.flush(); i am using hibernate 3.3.1 and I kept hibernate3.jar 

Hibernate Questions

Need for hibernate - Hibernate
solution. In Jdbc we use .properties file and in hibernate we use .xml file...Need for hibernate  Can anyone say why should we go for hibernate?   Hi friend, Advantages of hibernate : It is based on object 

Hibernate Questions

hibernate code problem - Hibernate
hibernate code problem  suppose i want to fetch a row from the table... it plz give the complete code  Hi friend, I am sending you a link . Please visit for more information. http://www.roseindia.net/hibernate 

Hibernate Questions

Java - Hibernate
, this type of output. ---------------------------- Inserting Record Done Hibernate... FirstExample { public static void main(String[] args) { Session session = null... = null; try{ // This step will read hibernate.cfg.xml and prepare hibernate 

Hibernate Questions

hibernate code - Hibernate
hibernate code  sir, i have tried ur hibernate 3.0 firt example code, i have done as u have told in the tutorial like import all the related jar files,made asimple java project and copied the two xml files into src/bin 

Hibernate Questions

hibernate code problem - Hibernate
hibernate code problem  String SQL_QUERY =" from Insurance...: " + insurance. getInsuranceName()); } in the above code,the hibernate... thanks shakti  Hi friend, Your code is : String SQL_QUERY =" from 

Hibernate Interview Questions

Hibernate Code - Hibernate Interview Questions
Hibernate Code   Hi Friends, In Hibernate, wat is Annotation. There is no need of hibernate configuration file in hibernate version 3 - right . but hbm is necessary for all versions 

Hibernate Questions

hibernate code - Hibernate
hibernate code  well deepak,Regarding the inputs u asked for my fisr question, i have downloaded the complete project from the roseindia site...{ // This step will read hibernate.cfg.xml and prepare hibernate for use SessionFactory 

Hibernate Questions

Hibernate code problem - Hibernate
Hibernate code problem  Hai, iam working on simple login application using hibernate in spring. I've used Spring dependency injection too.I.... Please find my src code here... ----------------controller Layer 

Hibernate Questions

Hibernate application - Hibernate
Hibernate application  Hi, Could you please tell me how to implement hibernate application in eclipse3.3.0 Thanks, Kalaga.  Hi Friend, Please visit the following link: http://www.roseindia.net/hibernate 

Hibernate Questions

JAVA - Hibernate
is flexible and powerful ORM solution to map Java classes to database tables. Hibernate... of by the developer manually with lines of code. Hibernate provides transparent persistence...JAVA  hello friends please answer me. 1. what is hibernate...? 2 

Hibernate Interview Questions

Hibernate Code - Hibernate Interview Questions
Hibernate Code  This is the question asked in CAPEGEMINI Write a sample code how to persist inner class,interface,final class and how to invoke stored procedure in hibernate? From Surjeet 

Hibernate Questions

hibernate web project - Hibernate
links: http://www.roseindia.net/hibernate/index.shtml http://www.roseindia.net/hibernate/runninge-xample.shtml http://www.roseindia.net/struts/struts...hibernate web project  hi friends,very good morning,how to develop 

Hibernate Questions

hibernate - Hibernate
I am sending links to you where u can find the solution regarding your query: http://www.roseindia.net/hibernate/hibernate-aggregate-functions.shtml http://www.roseindia.net/hibernate/associations-and-joins.shtml Thanks 

Hibernate Questions

Hibernate - Hibernate
not understandable for anybody learning Hibernate. Hibernate provides a solution to map... one example   Hi mamatha, Hibernate 3.0, the latest Open Source... from Hibernet.org.Hibernate is a solution for object relational mapping 

Hibernate Questions

Compilation error. Hibernate code - Hibernate
Compilation error. Hibernate code   Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory at org.hibernate.cfg.Configuration.(Configuration.java:152) at com.sat.Manager.main(Manager.java:10 

Hibernate Questions

java - Hibernate
/hibernate/runninge-xample.shtml Thanks...java  HI guys can any one tell me,procedure for executing spring and hibernate in myeclipse ide,plz very urgent for me,thank's in advance.   

Hibernate Questions

Is buildSessionFactory() deprecated in hibernate 4?
Is buildSessionFactory() deprecated in hibernate 4?  Hi, I am trying to develop an application in Hibernate 4. I am using the Hibernate 4.3.0.final build. Following code is given is the Hibernate documentation: SessionFactory 

Hibernate Questions

Hibernate - Hibernate
Hibernate  Hello Deepak as you answer posted this is solution of if any file not found but my question is .. Error is ::: Error in reading contact.hbm.xml contact.hbm.xml is my hibernate mapping file. So please read 

Hibernate Questions

Hibernate - Hibernate
Hibernate  What is a lazy loading in hibernate?i want one example of source code?plz reply 

Hibernate Questions

Hibernate - Hibernate
Hibernate  I am trying to connect hibernate with ejb2.0 stateless session bean, my application sucessfully deploy in weblogic server but when i... net.sf.hibernate.cfg.Configuration . Please give a solution for that.  

Hibernate Questions

Hibernate - Hibernate
to aracle server with IP 192.168.1.3 using hibernate(Schema name :mdm) So here i...Hibernate   Dear sir Thanks for your previous answers its really... ,hibernate, jboss, oracle) one is 1) Express and 2) MDM(All master data 

Hibernate Interview Questions

Hibernate sample code - Hibernate Interview Questions
Hibernet.org.The Hibernate 3.0 core is 68,549 lines of Java code together with 27,948 lines...Hibernate sample code  Hi Can any body tell me how to persist inner class,abstract class,final class,and interface in hibernate. From 

Hibernate Questions

Hibernate Criteria Transformer Example code
Hibernate Criteria Transformer Example code  Hello, I am trying to find the example of Hibernate Criteria Transformer. Tell me the good tutorial of Hibernate Criteria Transformer with source code. Thanks   Hi, Check 

Hibernate Questions

Hibernate - Hibernate
Hibernate  when I run Hibernate Code Generation wizard in eclipse I'm getting the following error. I added ojdbc14.jar to my build path. Still I'm.../hibernate/index.shtml Hope that it will be helpful for you. Thanks 

Hibernate Questions

Hibernate - Hibernate
Hibernate SessionFactory  Can anyone please give me an example of Hibernate SessionFactory?  Hi friend,package roseindia;import... { } }}--------------------------  This is mapping code,<?xml version=" 

Programming Tutorials

HIBERNATE- BASICS
HIBERNATE- BASICS  (R.S.Ramaswamy)- ( in 3 parts) (part-1) ( CMP-EJB vs. HIBERNATE) (published in DeveloperIQ-July-2005... is agog with excitement about a very popular open-source technology , Hibernate 

Hibernate Questions

hibernet code - Hibernate
 

Hibernate Questions

Hibernate criteria count.
to map to the database table. Here is the code of Employee.java ? Next create...(0)); } } Description: Hibernate criteria is used here as alternative to HQL...Hibernate criteria count.  How do we count rows using criteria 

Hibernate Questions

hibernate Configuration with eclpse 3.1 - Hibernate
/hibernate/runninge-xample.shtml http://www.roseindia.net...hibernate Configuration with eclpse 3.1  Dear Sir, i m developing a program using hibernate with struts. but i am not able to configure 

Java Beginners

Please can I get the code for solution of producer consumer problem using semaphores?
Please can I get the code for solution of producer consumer problem using semaphores?  Please can I get the code for solution of producer consumer problem using semaphores?   import java.util.*; class Semaphore 

XML Questions

Need Solution to get vaues from sql database in java
Need Solution to get vaues from sql database in java  hi I have written a code in java to get these xml tags < company comp:loc=" "/> now i... file. please provide me solution to get values for xml tags from database 

SQL Question

Solution to get vaues for xml tags fform sql database in java
Solution to get vaues for xml tags fform sql database in java  hi I have written a code in java to get these xml tags < company comp:loc=" "/>... in separate file. please provide me solution to get values for xml tags from 

Java Beginners

solution to get values for xml namespace tags from sqldatabase in java
solution to get values for xml namespace tags from sqldatabase in java  hi I have written a code in java to get these xml tags < company comp:loc... tags in separate file. please provide me solution to get values for xml tags 

JDBC Questions

Want solution to get values for xml namespace tags from database in java
Want solution to get values for xml namespace tags from database in java  hi I have written a code in java to get these xml tags < company comp... xml tags in separate file. please provide me solution to get values for xml tags 

Hibernate Questions

myJSF,Hibernate and Spring integration code is not working. - Hibernate
myJSF,Hibernate and Spring integration code is not working.  the code given in this url : http://www.roseindia.net/roseindiamembers/login.php i have tried but it does not work. when i write http://localhost 

Hibernate Questions

this is a hibernate question
this is a hibernate question  connection pooling code in hibernate 

Hibernate Questions

this is a hibernate question
this is a hibernate question  connection pooling code in hibernate 

Hibernate Questions

this is a hibernate question
this is a hibernate question  connection pooling code in hibernate 

Hibernate Questions

Hibernate 1 - Hibernate
Hibernate 1  what is a fetchi loading in hibernate?i want source code?plz reply 

Hibernate Questions

Java Compilation error. Hibernate code problem. Struts first example - Hibernate
Java Compilation error. Hibernate code problem. Struts first example  Java Compilation error. Hibernate code problem. Struts first example 

Hibernate Questions

Hibernate Criteria Query Example with source code
good example of Hibernate Criteria Query Example with source code? Thanks   Here is good Example program of Hibernate Criteria Query with source code. The source code of the Hibernate Criteria Query will help you in grasping 

Development process Questions

SOLUTION: How to compile Objective C on Windows with GNU Step ?
SOLUTION: How to compile Objective C on Windows with GNU Step ?  <..., except the fact that the above program needs some more instructions to run. Here...;p>Following are code files in the above mentioned User path: MyClass.h 

Hibernate Questions

Hibernate tutorial - Hibernate
Hibernate tutorial  can u provide me some material in hibernate.  Hello Rohin,You can learn Hibernate within 10 days from our website. In our hibernate tutorial you will find many examples with running code. You can 

Hibernate Questions

Hibernate Annotattions - Hibernate
Hibernate Annotattions  Can anybody tell me here how we can use hibernate annotations which is a new facility in hibernate 3.2 any tutorial and what.... The Hibernate Annotations is the powerful way to provide the metadata for the Object 

Hibernate Interview Questions

Hibernate:What is Hibernate proxy?
is created by default by Hibernate, for mapping a class to a file. The code to invoke...Hibernate:What is Hibernate proxy?  What is Hibernate proxy?   Proxy means the authority to represent someone else In hibernate, you can 

Hibernate-Tutorials

hibernate sample code
This section contains a simple Hibernate 4 example using Annotation with source code. The eclipse id and Apache Tomcat is used in this example 

Hibernate Questions

Hibernate DetachedCriteria mutiple results in java
Hibernate DetachedCriteria mutiple results in java  This is the SQL... BY USERPROFILE.FIRSTNAME And I'm trying to execute the code below that I thought the equivalent to hibernate DetachedCriteria and expected to only have two data 

Hibernate Questions

Hibernate Isolation Query. - Hibernate
Hibernate Isolation Query.  Hi, Am Using HibernateORM with JBOSS server and SQLSERVER.I have a transaction of 20 MB, when it is getting processed... the records from that table. Which not happening now ? I want to have the solution 

Hibernate Questions

j2eee(Hibernate) - Hibernate
j2eee(Hibernate)  Hi, This is jagadhish.Iam learning Hibernate.I... relations in Hibernate(with examples).But not showing the link available... any problem. Please specify in detail and send me code. I am sending you 

Development process Questions

Wimax solution
 

JSP Servlet Questions

jsp solution
 

Hibernate-Tutorials

Hibernate saveOrUpdate Method
() method can be used in Hibernate. For this I am giving a complete source code... and update the record of table according to the identifier. Complete Code...Hibernate saveOrUpdate Method In this tutorial you will learn about 

Hibernate-Tutorials

Hibernate update Method
in Hibernate. For this I am giving a complete source code which can be downloaded... an update method of Hibernate to update the record of table. Complete Code...Hibernate update Method In this tutorial you will learn about the update 

Hibernate Interview Questions

Hibernate: core interfaces of hibernate framework
Hibernate: core interfaces of hibernate framework  What are the core interfaces of hibernate framework   Most of hibernate based application code deals with following interfaces provided by the Hibernate Core 

Hibernate Questions

C3P0 with Hibernate
C3P0 with Hibernate  How to use C3PO with Hibernate? Thanks   Hi, Please check the tutorial C3P0 Hibernate. In this page we have source code example of using C3P0 with Hibernate. Thanks 

Hibernate Tutorial Example

Complete Hibernate 3.0 and Hibernate 4 Tutorial
Complete Hibernate 3.0 and Hibernate 4 Tutorial   .../relational mapping solution for Java. Download Source Code Example of tutorial Basics... will show you how to run the example code.   Hibernate Introduction 

Hibernate Questions

Could not read mappings from resource: e1.hbm.xml - Hibernate
code, hibernate mapping was not correct. i am sending hibernate mapping code... /*tHIS IS THE HIBERNATE cONFIGURATION*/ /*THIS IS THE HIBERNATE 

Hibernate-Tutorials

hibernate by example
In this tutorial you will learn hibernate by example with ready made downloadable source code 

Hibernate-Tutorials

Hibernate persist Method
of Hibernate to insert record to the table. Complete Code : Employee.java... am giving a complete source code which can be downloaded. To achieve...Hibernate persist Method In this tutorial you will learn about how to use 

Hibernate Tutorial Example

Hibernate
. We have tried to provide many articles, examples and code at our Hibernate 4...Hibernate Hibernate is a framework for Java technology, which is used.... Hibernate is Java library which is used to develop the data access layer 

Java Magazine Questions

Need solution to get values for XML namespace tags from SQL database in Java
Need solution to get values for XML namespace tags from SQL database in Java  hi I have written a code in java to get these xml tags < company... and created xml tags in separate file. please provide me solution to get values for xml 

Hibernate Questions

java(Hibernate) - Hibernate
java(Hibernate)  Hai Amardeep This is jagadhish.Iam giving full code... will read hibernate.cfg.xml and prepare hibernate for use SessionFactory... for more information. http://www.roseindia.net/hibernate/ Thanks Amardeep 

Hibernate Tutorial Example

Hibernate 4
of deprecated code You can also migrate your Hibernate 3 code to Hibernate 4... examples on Hibernate 4. All the examples are supported with the source code...Hibernate 4 Hibernate 4 is the latest version of Hibernate which was released 

Hibernate Questions

Hibernate Question
Hibernate Question  Hi,i am doing hibernate mapping but i did not get the accurate concept of that so will you please send me a mapping between 2 table code. and at the time of mapping where we have to use the set<> method 

Hibernate Tutorial Example

Hibernate Tutorial: Learn Hibernate with examples
of articles and example programs given here. Hibernate is popular open source ORM... ORM framework. Here are the Hibernate tutorial topics that you can learn... Hibernate Tutorial: Concise tutorial of Hibernate framework 

Hibernate Questions

Hibernate required jar files - Hibernate
Hibernate required jar files  Hi, What are the jar files are required for hibernate and Springs application. I want to run complete application springs and hibernate. Where it will be available? How can i use it i.e. 

Hibernate Questions

Null pointer exception in hibernate - Hibernate
Null pointer exception in hibernate  Hi i am getting null pointer exception.while running the program in hibernate... exception. SessionFactory object is not creating pls give me the solution 

Hibernate Questions

java - Hibernate
the code and run using Hibernate and annotation..plse help me...  Hi friend, Read for more information. http://www.roseindia.net/hibernate/hibernateannotations/hibernate-annotations-tutorial.shtml Thanks 

Development process Questions

spring hibernate
table through jsp using spring an hibernate....and the fields in the registration jsp are in different tables???can any one help or is there any sample code... the following link: http://www.roseindia.net/hibernate/HibernateSpring.shtml 

Development process Questions

spring hibernate
table through jsp using spring an hibernate....and the fields in the registration jsp are in different tables???can any one help or is there any sample code... the following link: http://www.roseindia.net/hibernate/HibernateSpring.shtml 

Hibernate Questions

hibernate configuration with eclipse 3.1 - Hibernate
simple hibernate program code and with struts also. so please tell me the step by step process. i have that folder in d:/hibernate i thing...hibernate configuration with eclipse 3.1  Dear Sir, i got your mail 

PHP Questions

solution of k map in c
solution of k map in c  write a program in c to solve k-map with digital circuit 

Advertisements Advertisements
 

 

 

DMCA.com