hibernate firstExample not inserting data

hibernate firstExample not inserting data

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("nissanB[email protected]");
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("[email protected]");
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
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-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, 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
Hibernate Data types
This section lists Hibernate data types
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
Version of com.emsoft>emsoft-data-hibernate dependency
List of Version of com.emsoft>emsoft-data-hibernate dependency
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
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...;FORM ENCTYPE="multipart/form-data"  ACTION="UploadPDF.jsp"
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
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
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
Maven Dependency emsoft-data-hibernate >> 1.0.0
You should include the dependency code given in this page to add Maven Dependency of com.emsoft >> emsoft-data-hibernate version1.0.0 in your project
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
Maven Repository/Dependency: com.emsoft | emsoft-data-hibernate
Maven Repository/Dependency of Group ID com.emsoft and Artifact ID emsoft-data-hibernate. Latest version of com.emsoft:emsoft-data-hibernate dependencies. # Version Release Date You can
Maven Repository/Dependency: org.beangle.data | beangle-data-hibernate
Maven Repository/Dependency of Group ID org.beangle.data and Artifact ID beangle-data-hibernate. Latest version of org.beangle.data:beangle-data-hibernate dependencies. # Version Release Date
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
inserting image into database
inserting image into database  how to insert image into database using struts frame work and spring JDBC
Maven Repository/Dependency: eu.ralph-schuster | data-hibernate
Maven Repository/Dependency of Group ID eu.ralph-schuster and Artifact ID data-hibernate. Latest version of eu.ralph-schuster:data-hibernate dependencies. # Version Release Date 1
Maven Dependency emsoft-data-hibernate >> ${project.parent.version}
You should include the dependency code given in this page to add Maven Dependency of com.emsoft >> emsoft-data-hibernate version${project.parent.version} in your project
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
Inserting id in place of name to database
Inserting id in place of name to database  Hello, I have a database department where I have "id" and "name". I am fetching this data to a jsp form in dropdown list displaying "name" there and Now I wanted to insert data from
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
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
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 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
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
Insert Data in Table Using Stored Procedure
Insert Data in Table Using Stored Procedure        In this example we are inserting data into a table using stored procedure. Steps: 1.Create database
io.micronaut.data - micronaut-data-tx-hibernate version 4.0.0-M8 Maven dependency. How to use micronaut-data-tx-hibernate version 4.0.0-M8 in pom.xml?
io.micronaut.data  - Version 4.0.0-M8 of micronaut-data-tx-hibernate... of micronaut-data-tx-hibernate in pom.xml? How to use micronaut-data-tx-hibernate...-data-tx-hibernate in project by the help of adding the dependency in the pom.xml
io.micronaut.data - micronaut-data-tx-hibernate version 4.0.0-M8 Maven dependency. How to use micronaut-data-tx-hibernate version 4.0.0-M8 in pom.xml?
io.micronaut.data  - Version 4.0.0-M8 of micronaut-data-tx-hibernate... of micronaut-data-tx-hibernate in pom.xml? How to use micronaut-data-tx-hibernate...-data-tx-hibernate in project by the help of adding the dependency in the pom.xml

Ads