Ok, I just solved this by instantiating a new object from my Factory: TABLERecord r = factoryObj.newRecord(TABLE); r.set(...); r.store(); // r is already updated with the automatically generated ID
System.out.println(r.ID); I had an error on the primary key being null, probably because I instantiated a record as a regular Object: new TABLERecord(), and in doing so the primary key was automatically set to null, leading to the error. I hope my mistake will be useful to others. P.S. I wrote the reply before your post. I tried using the InsertQueryclass, but I had the same error, possibly for the same reason (the ID was set to dirty, from what I have understood from the docs and other posts here). Thank you! On Friday, February 15, 2013 11:33:53 AM UTC+1, Lukas Eder wrote: > > Hi Francesco, > > > I am using the generated POJOs and DAOs to retrieve and store objects in > my > > database. I know that, for "regular" INSERTs, I can use the returning() > > method, but how can I retrieve the inserted object? There is a sequence > for > > the ID, which is automatically generated by the database and I would > like to > > get back. > > I would like to know if I can avoid using DAOs and do a simple > > factory.insert(TABLE, TABLERecord) so I can use the returning() right > there. > > Yes you can. I've just noticed that the API for such operations is a > bit clumsy, though. You'll have to resort to using jOOQ's internal > model (a.k.a. non-DSL API, classic API, model API) for that. Here's an > example: > > TableRecord record = // ... your record > InsertQuery<TableRecord> insert = factory.insertQuery(TABLE); > insert.addRecord(record); > insert.setReturning(); > insert.execute(); > TableRecord result = insert.getReturnedRecord(); > > Inserting (and updating) pre-existing Records through the DSL API > should be possible, though. I've added feature request #2199 for this: > https://github.com/jOOQ/jOOQ/issues/2199 > > Cheers > Lukas > -- You received this message because you are subscribed to the Google Groups "jOOQ User Group" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
