java - jooq insert throws an exception when another thread is reading from same table -
i have table inserting records using record.insert() method. believe method doing insert , select in different transactions. @ same time have thread pools table records processes them , deletes them.
in cases getting below exception:
org.jooq.exception.nodatafoundexception: 1 row expected refresh. record not exist in database. @ org.jooq.impl.updatablerecordimpl.refresh(updatablerecordimpl.java:345) @ org.jooq.impl.tablerecordimpl.getreturningifneeded(tablerecordimpl.java:232) @ org.jooq.impl.tablerecordimpl.storeinsert0(tablerecordimpl.java:208) @ org.jooq.impl.tablerecordimpl$1.operate(tablerecordimpl.java:169) my solution use dsl.using(configuration()).insertinto instead of record.insert().
my question shouldn't insert , fetch done in same transaction?
update: dropwizard app using jooqbundle: com.bendb.dropwizard:dropwizard-jooq.
the configuration injected in dao, insert follows:
r object = // jooq record object.attach(configuration); object.insert(); on second thread selecting records table, processing them , deleting them
jooq logs shows 2 queries not run in same transaction:
14:07:09.550 [main] debug org.jooq.tools.loggerlistener - -> bind values : insert "queue" .... 14:07:09.083', 1) 14:07:09.589 [main] debug org.jooq.tools.loggerlistener - affected row(s) : 1 14:07:09.590 [main] debug org.jooq.tools.stopwatch - query executed : total: 47.603ms 14:07:09.591 [main] debug org.jooq.tools.stopwatch - finishing : total: 48.827ms, +1.223ms 14:07:09.632 [main] debug org.jooq.tools.loggerlistener - executing query : select "queue"." i not see "autocommit off" or "savepoint" statements in logs printed jooq in case queries run in transaction. hope helps, let me know if need more info
update 2:
jooq version 3.9.1 mysql version 5.6.23
database , jooq entry yml file:
database: driverclass: com.mysql.jdbc.driver user: *** password: *** url: jdbc:mysql://localhost:3306/myschema properties: charset: utf-8 characterencoding: utf-8 # maximum amount of time wait on empty pool before throwing exception maxwaitforconnection: 1s # sql query run when validating connection's liveness validationquery: "select 1" # timeout before connection validation queries fail validationquerytimeout: 3s # initial number of connections initialsize: 25 # minimum number of connections keep open minsize: 25 # maximum number of connections keep open maxsize: 25 # whether or not idle connections should validated checkconnectionwhileidle: true # amount of time sleep between runs of idle connection validation, abandoned cleaner , idle pool resizing evictioninterval: 10s # minimum amount of time connection must sit idle in pool before eligible eviction minidletime: 1 minute jooq: # flavor of sql generate. if not specified, inferred jdbc connection url. (default: null) dialect: mysql # whether write generated sql logger before execution. (default: no) logexecutedsql: no # whether include schema names in generated sql. (default: yes) renderschema: yes # how names should rendered in generated sql. 1 of quoted, as_is, lower, or upper. (default: quoted) rendernamestyle: quoted # how keywords should rendered in generated sql. 1 of lower, upper. (default: upper) renderkeywordstyle: upper # whether generated sql should pretty-printed. (default: no) renderformatted: no # how parameters should represented. 1 of indexed, named, or inline. (default: indexed) paramtype: indexed # how statements should generated; 1 of prepared_statement or static_statement. (default: prepared_statement) statementtype: prepared_statement # whether internal jooq logging should enabled. (default: no) executelogging: no # whether optimistic locking should enabled. (default: no) executewithoptimisticlocking: yes # whether returned records should 'attached' jooq context. (default: yes) attachrecords: yes # whether primary-key fields should updatable. (default: no) updatableprimarykeys: no have included jooq bundle in application class described in https://github.com/benjamin-bader/droptools/tree/master/dropwizard-jooq. using https://github.com/xvik/dropwizard-guicey inject configuration each dao. guide module has following binding:
bind(configuration.class).toinstance(jooqbundle.getconfiguration());
Comments
Post a Comment