Hello, My 2 cents on this > Well, Hibernate solves this like so: If the PK is null, the identity > generator is started to assign a PK (well, I simplify but you get the idea) > and an INSERT will happen. If the PK is not null, it will UPDATE. > > I guess it would work if the PK is based on a sequence, but it is not uncommon to have non auto-increment PKs, how would hibernate do it in this case?
> This feels natural because it uses the assumption that you can't have a PK > unless the record has been read from the DB. And if you have a PK, then the > DB must already know about it. > > Again, if my primary key is a user name, an email, a region or some shipping code, I'd be unable to insert... > So maybe a good solution would be to modify jOOQ to support a similar > behavior. With my suggested changes in the Configuration class, it would be > simple to add the PK generator to it. Everything else should then be a > purely internal change of the logic. > > I'd prefer having a factory method with some DSL such as TAuthorRecord author = Factory.updateRecord(T_AUTHOR).wherePk( AuthorId ); rather than letting some obscure logic decide. Compared to record-level methods like markAsNew(), storeAsUpdate, storeAsNew this would not confuse internal states, dirty fields tracking and such.
