• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Saloon Keeper
Posts: 10732
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 https://coderanch.com/t/219259/ORM/databases/insert-doesn-work-hibernate
 
Carey Brown
Saloon Keeper
Posts: 10732
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic