Note. I do not use the Jooq code generator
In the DAO unit test, the DAO checks that after the object has been inserted, the DAO sets the identifier returned by last_insert_id () from the database. Not related to the actual database, since I use MockConnection and MockDataProvider from JOOQ.
When the DAO does the following:
DSLContext ctx = DSL.using(connection, SQLDialect.MYSQL);
//insert
//get id
BigInteger id = ctx.lastId();
JOOQ executes the following query:
select last_insert_id() from dual;
In my MockDataProvider, I check when this request is executed, and return the result accordingly:
import static org.jooq.impl.DSL.dual;
@Override
public MockResult[] execute(MockExecuteContext ctx) throws SQLException {
Field<BigInteger> id = DSL.field("", BigInteger.class);
Record record = dual().newRecord();
record.setValue(id, BigInteger.valueOf(1234567));
return new MockResult[] { new MockResult(record) };
}
When the MockResult returned above returns, I get the following exception
java.lang.IllegalArgumentException: Field () is not contained in Row ()
What is the correct way to populate MockResult for request last_insert_id ()?