Home > Back-end >  Automatically attach new records
Automatically attach new records

Time:04-14

Is it possible to attach a default configuration for creating new records instead of manually attaching each time? I saw that while performing a SELECT it automatically attaches the record, would be nice if I could skip this step for every new record created.

var address = new AddressRecord();
address.attach(jooq().configuration());
address.setAddress(addressTemplate.getAddress());
address.setState(addressTemplate.getState());
address.setCity(addressTemplate.getCity());
address.setZipcode(addressTemplate.getZipcode());
address.setCountryId(addressTemplate.getCountryId());

CodePudding user response:

Due to the nature of a Java constructor call (new AddressRecord()), it is not possible to intercept such a call e.g. in order to attach the resulting object to a Configuration.

But you can use jooq().newRecord(ADDRESS) instead, which produces an attached record. You can also use jooq().newRecord(ADDRESS, addressTemplate) to copy values using the DefaultRecordUnmapper

  • Related