简体   繁体   中英

Inserting record in jOOQ without specifying column names

I have a table USER_ROLES that has 5 columns. Also, a class UserRole that has the same number of fields and names as USER_ROLES.

I'm trying to insert a row without specifying the column names:

    UserRole ur = new UserRole();
    // UserRole fields setting

    create.insertInto(USER_ROLES).values(ur).execute();

But I get this error when I attempt to create the row:

The number of values must match the number of fields

Am I forced to specify the column names?

If you have generated the UserRolesRecord , and if your UserRole class follows the naming conventions defined by DefaultRecordMapper , then you can load your custom UserRole content into the record like this:

UserRole ur = new UserRole();
// ...
UserRoleRecord rec = new UserRoleRecord();
rec.from(ur);
create.insertInto(USER_ROLES).set(rec).execute();

You can do the following (simpler):

UserRole ur = new UserRole();
create.insertInto(USER_ROLES).set(ur).execute();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM