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

  • Home
  • SEARCH
  • 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 6026481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:27:04+00:00 2026-05-23T04:27:04+00:00

I have the following Model class: package com.swaranga.model; public final class Book { private

  • 0

I have the following Model class:

package com.swaranga.model;

public final class Book
{
    private Long id;
    private String title;
    private String isbn;

    public Book(){}

    public Book(String title, String isbn)
    {
        this.title = title;
        this.isbn = isbn;
    }

    public final Long getId(){
        return id;
    }

    private final void setId(Long id)
    {
        this.id = id;
    }


    public final String getTitle()
    {
        return title;
    }


    public final void setTitle(String title)
    {
        this.title = title;
    }


    public final String getIsbn()
    {
        return isbn;
    }


    public final void setIsbn(String isbn)
    {
        this.isbn = isbn;
    }
    //assume valid equals and hashcode
}

The have the following mapping file Book.hbm.xml:

<hibernate-mapping>

        <class name="com.swaranga.model.Book" table="book">
            <id name="id" type="long">
                <generator class="native"/>
            </id>

            <property name="title" column="title" type="string"/>

            <property name="isbn" column="isbn" type="string"/>
        </class>

</hibernate-mapping>

The following database schema:

    CREATE TABLE  `hibernatetest`.`book` (
      `id` int(10) unsigned NOT NULL auto_increment,
      `title` varchar(45) NOT NULL,
      `isbn` varchar(45) NOT NULL,
      PRIMARY KEY  (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;

The following hibernate config file:

<hibernate-configuration>
    <session-factory>
        <property name="connection.driver_class">com.mysql.jdbc.Driver </property>          
        <property name="connection.url">jdbc:mysql://localhost:3306/HibernateTest </property>

        <property name="connection.username"> root </property>

        <property name="connection.password"> latitude </property>

        <property name="show_sql">true</property>

        <property name="dialect">org.hibernate.dialect.MySQLDialect </property>

        <property name="myeclipse.connection.profile">mysql</property>

        <mapping resource="com\swaranga\model\Book.hbm.xml" />
    </session-factory>
</hibernate-configuration>

And finally the following code to persist a Book object:

public class Main
{
    public static void main(String[] args)
    {
        File f = new File("hibernate.cfg.xml");     
        Configuration cfg = new Configuration();
        SessionFactory sessionFactory = cfg.configure(f).buildSessionFactory();     
        Session s = sessionFactory.openSession();       
        s.beginTransaction();       
        s.save(new Book("JDBC", "ISBN_!@#"));       
        s.flush();      
        s.disconnect();
    }
}

I am getting the following output in the console:

Hibernate: insert into book (title, isbn) values (?, ?)

But when I check my database, there are no entries.

Apologies for such a long question, but I felt necessary to supply all the details. Please help. Thanks in advance.

  • 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-23T04:27:05+00:00Added an answer on May 23, 2026 at 4:27 am

    Try editing the end of your main method to this:

    Transaction tx = s.beginTransaction();       
    s.save(new Book("JDBC", "ISBN_!@#"));       
    tx.commit();
    s.flush();      
    s.disconnect();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following classes: package models; public class Test extends activejdbc.Model { }
I have following model class in my application: public class Dispute { public long
Let's say I have the following model: class Contest: title = models.CharField( max_length =
i have the following classes: //Product class public class Product { @Id @GeneratedValue private
I have the following model : class Contract { string ContractID{get;set;} ICollection<Part> Parts{get;set;} }
I have the following model: public class Blog { public int BlogID { get;
I have a following model: class Car(models.Model): make = models.CharField(max_length=40) mileage_limit = models.IntegerField() mileage
I have the following Django and Flex code: Django class Author(models.Model): name = models.CharField(max_length=30)
Say I have the following in my models.py : class Company(models.Model): name = ...
I have the following classes: Ingredients, Recipe and RecipeContent... class Ingredient(models.Model): name = models.CharField(max_length=30,

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.