aspose file tools*
The moose likes Object Relational Mapping and the fly likes Seems to insert but doesn't end up in the database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Seems to insert but doesn Watch "Seems to insert but doesn New topic
Author

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

Carey Brown
Ranch Hand

Joined: Nov 19, 2001
Posts: 187

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

Joined: Jul 20, 2005
Posts: 10207
    
166

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


[My Blog] [JavaRanch Journal]
Carey Brown
Ranch Hand

Joined: Nov 19, 2001
Posts: 187

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:

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Seems to insert but doesn't end up in the database