Generate equals and hashCode in Record using tables primary key

Simon Martinelli :

Is there a way to tell jOOQ to generate equals() and hashCode() using the primary key of its table?

The use case is:

I'm using Records in Vaadin Grids. I can refresh single items in the grid but Vaadin uses equals to find the corresponding item in the grid.

Now in the UI the user can select a record and edit it. And after edit I want to refresh the record in the grid. As far as I cans see jOOQ is using all fields for equals() and because the row was changed equals() is no longer true.

Lukas Eder :

jOOQ being a SQL based API assumes that a record is a tuple with no identity. Thus comparing a record with another record defaults to comparing each attribute of r1 with each corresponding attribute of r2.

This works the same way as a union between two sets works, or the distinct operation in SQL, both of which don't care about IDs but only about the record's values.

It should be simple to override the built-in equals() and hashCode() implementation for POJOs and records. jOOQ's internals should not depend on this implementation for most features (but there's a slight risk this is incorrect, I don't remember).

I have created a feature request for this: https://github.com/jOOQ/jOOQ/issues/8705. In the meantime, you will need to roll your own using a custom code section: https://www.jooq.org/doc/latest/manual/code-generation/codegen-custom-code/

Guess you like

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