jOOQ loadInto not throwing error on foreign key constraint fail

Viewed 120

I'm migrating some tables from a DB to another (MySql 5.7, jOOQ 3.10), and using the following code to insert:

try {
     myDatabase
         .loadInto(MYTABLE)
         .onErrorAbort()
         .batchAll()
         .loadRecords(rows)
         .fields(MYTABLE.fields())
         .execute();
 } catch (Exception e) {
     e.printStackTrace();
 }

This table has a FK constraint to another table, and the insert works if the other table is populated. However, if I don't populate the other table first, I don't get any errors, the program completes 'successfully', but no rows are inserted.

Trying to execute the same insert via terminal/datagrip gives me the expected FK error

Edit: also tried with .onErrorAbort() (added to the sample code)

1 Answers

You can check the errors of the loader by doing

// The errors that may have occurred during loading 
List<LoaderError> errors = loader.errors(); 
// loop if you want
LoaderError error = errors.get(0);
Related