• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

data inserting problem

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
i am new to the hibernate. i am trying to do some sample application with hibernate using HSQLDatabase. i am able to retriving the data from the database. but when i am trying to save the data in to the database.. it is not inserting.i am using increment as a generator class for Id.after executing the program it is showing following information in the console..

Hibernate: select max(id) from BOOK
Hibernate: insert into BOOK (bookname, id) values (?, ?)

but in the database it is not showing the inserted data.i am not getting any exception also. when i try to retrive the data from the database using Query.list()it is retriving normally.

please see the code bellow what i did:

main class:

session = HibernateUtil.getSessionFactory().openSession();
session.beginTransaction();
Book b1 = new Book();
b1.setLngBookId(1);
b1.setStrBookName("testData");
session.save(b1);
session.getTransaction().commit();

hbm file:

<hibernate-mapping>
<class name="test.Book" table="BOOK">
<id name="lngBookId" type="long" column="id" >
<generator class="increment"/>
</id>
<property name="strBookName">
<column name="bookname" />
</property>
</class>
</hibernate-mapping>

cfg file:

<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">org.hsqldb.jdbcDriver</property>
<property name="hibernate.connection.url">jdbc:hsqldb:file :\PAYMENTS\HSQLDB</property>
<property name="hibernate.connection.username">sa</property>
<property name="hibernate.connection.password"></property>
<property name="dialect">org.hibernate.dialect.HSQLDialect</property>
<property name="show_sql">true</property>
<mapping resource="book.hbm.xml"/>
</session-factory>
</hibernate-configuration>




please give me the solution to my problem.

Thanks & regards!!
Naresh Kapilavai
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try to remove this statement:

b1.setLngBookId(1);
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are not letting the mapping logic generate the next ID by setting the ID to 1 each time.
 
Nareshkumar Kapilavai
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your reply. i found the problem.problem is not with my code.it is something other problem with the database.when i change the database from HSQLDB to mysql it is working fine.Thank you very much.
 
He puts the "turd" in "saturday". Speaking of which, have you smelled this tiny ad?
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic