Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Hibernate hibernate firstExample not inserting data

Have Programming Question? Ask it here!
 
 
 


shabarish
hibernate firstExample not inserting data
3 Answer(s)      5 years and 10 months ago
Posted in : Hibernate



Advertisement
View Answers

October 22, 2008 at 3:59 PM


Hi friend,


Please send me code and explain in detail.


Visit for more information.

http://www.roseindia.net/hibernate/


Thanks.


October 23, 2008 at 8:08 AM


hi,
my hibernate.cfg.xml is
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">;

<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/hibernate</property>;
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<!-- Mapping files -->
<mapping resource="contact.hbm.xml"/>
</session-factory>
</hibernate-configuration>
my contact.hbm.xml is :
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">;
<hibernate-mapping>
<class name="roseindia.tutorial.hibernate.Contact" table="CONTACT">
<id name="id" type="long" column="ID" >
<generator class="assigned"/>
</id>

<property name="firstName">
<column name="FIRSTNAME" />
</property>
<property name="lastName">
<column name="LASTNAME"/>
</property>
<property name="email">
<column name="EMAIL"/>
</property>
</class>
</hibernate-mapping>
my FirstExample is :
/**
*
*/
package roseindia.tutorial.hibernate;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
/**
* @author shabarish
*
*/
public class FirstExample
{
public static void main(String as[])
{
Session session=null;
try {
//used to read hibernate.cfg.xml file
SessionFactory sessionFactory=new Configuration().configure().buildSessionFactory();
session=sessionFactory.openSession();
System.out.println("inserting records in Contact table");
Contact contactBO = new Contact();
contactBO.setId(5);
contactBO.setFirstName("nissan");
contactBO.setLastName("Bugati");
contactBO.setEmail("nissanBugati@shabarish.com");
session.save(contactBO);
System.out.println("After Save");
} catch (Exception e)
{
// TODO: handle exception
System.out.println(e.getMessage());
}finally{
// Actual contact insertion will happen at this step
session.flush();
session.close();

}

}
}
and my contact table is:
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
data is not inserting into DB


February 10, 2010 at 7:53 PM


Hi,

Just for testing that you are doing everything right and to see that data is being inserted into table,modify the code mentioned in the firstExample as below.
I will later post the actual code issue later.
here i am using transaction interface to make things work for you hope this helps.

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);
System.out.println("Done");
tx.commit();

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


}

}
}


Related Tutorials/Questions & Answers:
hibernate firstExample not inserting data - Hibernate
hibernate firstExample not inserting data  hello all , i followed... problem is data is not inserting into DB even though the program is executed... DEFAULT CHARSET=latin1 data is not inserting
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
Advertisements
help me in inserting data into db using hibernate
help me in inserting data into db using hibernate  How to insert data into dependent tables through hybernate   Hi Friend, Please visit the following link: http://www.roseindia.net/hibernate/insert-data-database.shtml
inserting data into datafields
inserting data into datafields  I was raised with a query.... there is a button, on click on it....... few fields regenerates and the details entered there should be inserted into Database Number of times we click that button
Inserting Data into mysql - SQL
Inserting Data into mysql  My sincere apologize for this post. I noticed there is no category for php. However am hoping my question will fit... (using php)and inserting the details in a mysql database. Lets take for instance
Problem in inserting clob data in jsp
Problem in inserting clob data in jsp  how to insert any rich text editor data (which have more than 32766 characters) in a clob type column of oracle database with jsp
Data is not inserting correctly in mysql database.
Data is not inserting correctly in mysql database.  Hello Sir, below is my code to insert data into database by list iteration... for each data cloumn ..at the time of end of the query... PLz see my code and point my
Inserting data in Excel File - Java Beginners
Inserting data in Excel File  Dear Sir, How can we fill the excel with fetched data from the database like Oracle, DB2? Is it possible to create an excel with filled data? Kindly give me the solutions to questions
inserting same data to different tables in oracle
inserting same data to different tables in oracle  Hi there ...! i have to insert un,pwd, to three oracle tables, like admin, user, stud, but i want pickup these table names from a drop down list in html...is there any chance can
inserting same data to different tables in oracle
inserting same data to different tables in oracle  Hi there ...! i have to insert un,pwd, to three oracle tables, like admin, user, stud, but i want pickup these table names from a drop down list in html...is there any chance can
inserting same data to different tables in oracle
inserting same data to different tables in oracle  Hi there ...! i have to insert un,pwd, to three oracle tables, like admin, user, stud, but i want pickup these table names from a drop down list in html...is there any chance can
inserting same data to different tables in oracle
inserting same data to different tables in oracle  Hi there ...! i have to insert un,pwd, to three oracle tables, like admin, user, stud, but i want pickup these table names from a drop down list in html...is there any chance can
inserting same data to different tables in oracle
inserting same data to different tables in oracle  Hi there ...! i have to insert un,pwd, to three oracle tables, like admin, user, stud, but i want pickup these table names from a drop down list in html...is there any chance can
inserting same data to different tables in oracle
inserting same data to different tables in oracle  Hi there ...! i have to insert un,pwd, to three oracle tables, like admin, user, stud, but i want pickup these table names from a drop down list in html...is there any chance can
problem on jsp, inserting data into table(mysql).
problem on jsp, inserting data into table(mysql).  hello friends, I have a problem in jsp.I want to insert data, which is given by user through... is in mysql.I want to use placeholder("?") to insert data into table.Plsssss help
Inserting data on a database in servlet - JSP-Servlet
Inserting data on a database in servlet  Hi I am following... to a databse by a servlet.I used the example in "Inserting Data In Database table... of a table,that is none of the data which i tried to enter into database by using
data (image ,audio) inserting to data base (oracle 10g) and retriving the same data from jsp
data (image ,audio) inserting to data base (oracle 10g) and retriving the same data from jsp   data (image ,audio) inserting to data base (oracle 10g) and retriving the same data from jsp with script of data base plz help me
Hibernate Data types
This section lists Hibernate data types
inserting data from radio buttons to database-ERROR - JSP-Servlet
inserting data from radio buttons to database-ERROR  hi, i have already changed the option field of table question. the code which you give me has the option field as options. but it is option in the table,so i changed
inserting data from radio buttons to database - JSP-Servlet
inserting data from radio buttons to database  hi, i am getting error in my code of feedback form. once i finished selecting all the radio buttons and when i click on delete button. it points to the answer.jsp. answer.jsp
inserting data from radio buttons to database - JSP-Servlet
inserting data from radio buttons to database  hi, my problem is as follows: i am creating a feedback form of a college. this feedback form will ask some question and students have to answer those question with the help
problem in inserting data in databases created in netbeans using jsp..
problem in inserting data in databases created in netbeans using jsp..  i am trying to make a virtual classroom website in jsp using netbeans.i...+")"); out.println("Data is successfully inserted!"); } catch(Exception e
problem in inserting data in databases created in ecplise using jsp
problem in inserting data in databases created in ecplise using jsp  <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ page import="java.sql.*" %> JS Soft
problem in inserting data in databases created in ecplise using jsp
problem in inserting data in databases created in ecplise using jsp  <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ page import="java.sql.*" %> JS Soft
How to save database data into excelsheet using hibernate
How to save database data into excelsheet using hibernate  How to save database data into excelsheet using hibernate
Problem in running first hibernate program.... - Hibernate
/FirstExample Exception in thread "main" " http://www.roseindia.net/hibernate/runninge... * * http://www.roseindia.net * Hibernate example to inset data into Contact table...Problem in running first hibernate program....  Hi...I am using
How to Make a Pdf and inserting data
How to Make a Pdf and inserting data  ... make a pdf file and how we can insert a data into the pdf file. This all... the file %> <BODY> <FORM ENCTYPE="multipart/form-data
Data fetch from multiple SQL tables - Hibernate
Data fetch from multiple SQL tables   I am in the process of writing my first hibernate application. I have a sql query that fetches data from multiple tables using left and right outer joins. I need to convert this JDBC data
Inserting Mysql CLOB data using Servlet
Inserting Mysql CLOB data using Servlet In this Section, we will insert "clob" data using "servlet". A CLOB is a Character Large Object in a Database table. CLOB data is used to store a block of text. It is designed
Inserting Data In Database table using Statement
Inserting Data In Database table using Statement... to insert the data in the database from our java program in the table stored... of the PrintWriter class. We can insert the data in the database only and only
Implementing Data Access Layer with Hibernate
Implementing Data Access Layer with Hibernate  ... we are using Hibernate to implement data access layer. Hibernate is an open... to save and retrieve the data in the form of Java objects from database. Hibernate
php inserting date into mysql
php inserting date into mysql  php inserting date into mysql  ..., data is a database table. <?php table $query_manual = "INSERT INTO data... = "INSERT INTO data(dp_name, dp_date) VALUE ('DATE: Auto CURDATE()', CURDATE
Struts2 and Hibernate Fetch Data Base Value
Struts2 and Hibernate Fetch Data Base Value  Hello Sir, I am...;AdminProvideLeave>(); try { > Query q = session.createQuery("from >...;AdminLeavePojo> adlp = null; > try { Query q = > session.createQuery
Struts2 and Hibernate Fetch Data Base Value
Struts2 and Hibernate Fetch Data Base Value  Hello Sir, I am...;AdminProvideLeave>(); try { > Query q = session.createQuery("from >...;AdminLeavePojo> adlp = null; > try { Query q = > session.createQuery
how to fetch data fron facebbok using spring batch and hibernate ?
how to fetch data fron facebbok using spring batch and hibernate ?  how to fetch data from facebbok using spring batch and hibernate ? Means i have to get all details of data from one source like facebook using id ans save all
how read excel data into database using struts2 with hibernate
how read excel data into database using struts2 with hibernate   hi friends, i am venkat i am started learning struts 2, please help me how to read excel data into database using struts2 with hibernate, please show me
inserting image into database
inserting image into database  how to insert image into database using struts frame work and spring JDBC
inserting value - JSP-Servlet
the database mySQl with the help of servlet. Inserting form data   Inserting form data into database using JSP and ServletGiven code will illustrate you...inserting value  sir i want to create a web application when we use
Java - Hibernate
, this type of output. ---------------------------- Inserting Record Done Hibernate... FirstExample { public static void main(String[] args) { Session session = null...(); System.out.println("Inserting Record"); Contact contact = new
How to insert data from textfields into database using hibernate?
How to insert data from textfields into database using hibernate?   try{ Session session = HibernateUtil.getSessionFactory().openSession...); System.out.println("Successfully data insert in database"); tx.commit
Insert Data in Table Using Stored Procedure
Insert Data in Table Using Stored Procedure        In this example we are inserting data...: To set the values we are using setXXX(). Here XXX is data type Object class name
How to display data from database in a TableView via Hibernate
How to display data from database in a TableView via Hibernate  I... at this. The classes: This is the Class that creates the database data object...;NewBeautifulKiwi> data; private List<NewBeautifulKiwi> initializeTable
Access data from mysql through struts-hibernate integration
Access data from mysql through struts-hibernate integration  Hi friends, I am making a program in which I want to access data from mysql through struts-hibernate integration. My search command is working properly but my
inserting picture in ms access
inserting picture in ms access  hi i am sanatan, how to insert picture in ms access by jsp.   <%@page import="java.sql.*,java.io.*"%>...()); pre.executeUpdate(); out.println("Inserting Successfully
Insert Data into Database Using Hibernate Native SQL
native sql for inserting data into database. Hibernate Native uses only... Insert Data into Database Using Hibernate Native SQL... how you can use Native SQL with hibernate. You will learn how to use Native
duplicate records inserting
duplicate records inserting  in the application i have provided the text filed on entering and submit the record is getting inserted. my question is i want to avoid duplicate values getting inserted. ex. i am inserting name
Hibernate Insert
This tutorial will help you to learn how to insert data into table by using hibernate
Hibernate code - Hibernate
Hibernate code  firstExample code that you have given for hibernate to insert the record in contact table,that is not happening neither it is giving... inserted in the database from this file. http://www.roseindia.net/hibernate
inserting dropdown values into database table
inserting dropdown values into database table   hi i want to insert dropdown values into a database table by using jsp
inserting multiple file formats into database
inserting multiple file formats into database  hi i want to insert multiple file format like .pdf.doc.zip into mysql database using jsp
 

 

 

DMCA.com