Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7586159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:21:23+00:00 2026-05-30T19:21:23+00:00

I did a small example program to insert data to a MySQL database table

  • 0

I did a small example program to insert data to a MySQL database table using java Hibernate. Every thing went fine & I got the result

“INFO: schema update complete
Hibernate: insert into items (itemcode, itemdiscription, itemprice, itemId) values (?, ?, ?, ?)
BUILD SUCCESSFUL (total time: 2 seconds)”

My mapping file & config file are OK.
But when I’m running the query in command prompt to fetch updated values it doesn’t show entered values by my java pojo class.
Why is that???
Please consider I have used netbeans 7.1 for this.

Mapping file

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"     "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
        <class name="firsthibernetapp.Item" table="items">
              <id name="iid" type="int" column="itemId" >
                 <generator class="assigned"/>
              </id>
              <property name="icode">
                    <column name="itemcode"/>
              </property>
              <property name="idiscription">
                     <column name="itemdiscription"/>
              </property>
              <property name="iprice">
                     <column name="itemprice"/>
              </property>
          </class>
</hibernate-mapping>

hibernet.cfg.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD     3.0//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      /combo</property>
  <property name="hibernate.connection.username">root</property>
  <property name="hibernate.connection.password">********</property>
  <property name="hibernate.connection.pool_size">10</property>
  <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
  <property name="current_session_context_class">thread</property>
  <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
  <property name="show_sql">true</property>
  <property name="hibernate.hbm2ddl.auto">update</property>
  <mapping resource="hibernate.hbm.xml"/>
  </session-factory>
  </hibernate-configuration>

Code:

package firsthibernetapp;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class FirstHibernetApp {

public static void main(String[] args) {
  Session session = null;
    try{
        SessionFactory sessionFactory = 
                 new Configuration().configure().buildSessionFactory();
        session =sessionFactory.openSession();
        Item item = new Item();
        System.out.println("Inserting Record");
        item.setIid(5);
        item.setIcode("FX00010");
        item.setIdiscription("Apple");
        item.setIprice(10);
        session.save(item);
        System.out.println("Done");
    }catch(Exception e){
        System.out.println(e.getMessage());
    }
    finally{
        session.flush();
        session.close();
     }
  }
}

`

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T19:21:24+00:00Added an answer on May 30, 2026 at 7:21 pm
    add these lines..
    session =sessionFactory.openSession();
    Transaction tx = session.beginTransaction(); //new line
    Item item = new Item();
    
    
    
    session.save(item);
     System.out.println("Done");
     tx.commit(); //new line
     }catch(Exception e){
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I did a small web application for using PHP, HTML, and JavaScript. I want
In an Oracle 10 database, I did a small test: SELECT REGEXP_REPLACE('İF', '[Iİ]F', 'DONE',
I have developed a small server that recives connections (using basically the example here:
Small example A <- c(kl, ck, nK, jk) B <- data.frame( CK = 1:10,
I have a small AJAX application, written in PHP that I did not secure
Did the recent purchase of MySQL by Sun and the subsequent buggy releases kill
I'm working on an small C++ example, to learn C++. Somebody wrote the main
For example, I have a small function that I want it to keep adding
I did a small app to make shipping bills, where a user enters the
I need implement simple search in small content table: id, name, description, content. Results

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.