Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Seems to insert but doesn't end up in the database

 
Carey Brown
Ranch Hand
Posts: 1380
16
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying what is essentially 'hello world' with Hibernate and a Derby database. I already have a Java/JDBC program that interacts with the database correctly and I'm trying to reproduce the project with Hibernate. So far I have only a single table that has a record id. I can populate the corresponding class with data and do a session.save() on it and everything is happy. Following that I have a session.createQuery().list() which lists all the records currently in the database and the brand new record that I just inserted. However, when I use Derby's IJ tool to do a select on the table, all the pre-existing rows are there but the new row is not. I'm guessing that the list() was pulling up the new row from some cache (?) and I'm not clear on how to make sure it gets physically written to the database.

Any help would be greatly appreciated.

-- Carey

 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code you are using doesn't create/commit transaction and in the absence of transactions, the data isn't added to the DB. This is a common problem that beginner's run into. Here's one previous thread which has a solution and a link to an article which explains the use of transactions http://www.coderanch.com/t/219259/ORM/databases/insert-doesn-work-hibernate
 
Carey Brown
Ranch Hand
Posts: 1380
16
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. That seems to have fixed the problem. I thought I had tried that in my thrashing about but apparently wasn't doing it correctly.
-- Carey

The new code:

 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic