jOOQ: Exclude column in update

ps0604 :

In this code I update a BOOKS row, trying not to set null the value of column TITLE because in myPojo is null and I don't want to override it (i.e. I attempt to exclude the column from the update):

        BooksRecord rec = new BooksRecord();
        rec.from(myPojo);               
        context.update(BOOKS)
           .set(rec)
           .set(BOOKS.TITLE, BOOKS.TITLE)
           .where(BOOKS.SK.eq(sk))
           .execute();

But this doesn't work, the TITLE column is set with null. Is there a way to make this work?

Lukas Eder :

Do it like this:

BooksRecord rec = new BooksRecord();
rec.from(myPojo);
rec.reset(BOOKS.TITLE);
rec.update();

The call to Record.reset(Field) resets the field's underlying Record.changed() flag prior to any further action, such as Record.update(), or when you copy the record's changed values into an Update statement like you did.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=295430&siteId=1