mvysny / vok-orm

Mapping rows from a SQL database to POJOs in its simplest form
MIT License
23 stars 4 forks source link

save() method raises exception on Postgresql DB #3

Closed akatecker closed 6 years ago

akatecker commented 6 years ago

Good evening! While trying to implement a simple CRUD application, I ran into an exception when calling the method save() in order to create a new row of data.

org.sql2o.Sql2oException: Keys where not fetched from database. Please call executeUpdate(true) to fetch keys

Looking up the internet, it seems to be a known problem of sql2o 1.5.4 when inserting a new row into a postgresql database (sql2o issue 170). As sql2o 1.6 is still not out, others have posted workarounds (... Adjustments and Fixes). I managed to solve my problem by reimplementing the method save() in my data class adding

con.createQuery("....",true)

Although other RDBMS seem not to be affected, I think it would be a great help for postgresql users to include this change into VoK ORM. Thank you again for the great work on VoK Best regards,

mvysny commented 6 years ago

Good morning :) I'm very happy that you like VoK and thanks for letting me know. I realized that I should run the test battery on all major databases, to quickly catch obvious bugs such as this one: #4

Let me look at this issue more closely.

mvysny commented 6 years ago

Fixed in vok-orm 0.3. The true parameter in createQuery() actually makes sense to be used for all databases since it mandates sql2o to return the generated key. So I guess PostgreSQL does the right thing and if false is passed in, it won't return the key.

mvysny commented 6 years ago

0.3 released, please try to upgrade and let me know if it helped.