As we know Hibernate
have a a very good feature SaveOrUpdate when we pass any object to this method it know data would be update
or new record will be added in database. Is this feature also available in JOOQ
Or in my code i have to handle this?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- SQL join to get the cartesian product of 2 columns
- sql execution latency when assign to a variable
- How to maintain order of key-value in DataFrame sa
jOOQ does the same. If you change the primary key of a record, then it will use
INSERT
, otherwise, it will useUPDATE
.As it is, when you read a record from the database, then calling
store()
will trigger anUPDATE
as you'd expect. If you create a new record, then it will beINSERT
ed.With 2.6, it's a bit hard to clone a record and then ask jOOQ to update it (since cloning will set the primary key in a new instance, hence marking it as "new" -> insert).
if you read a record from database and call record.store() you will have the same behavior of hibernate saveOrUpdate method, it's works perfectly!
But in the most of cases you will not read the record from the database, you will receive a record from a controller or a view for example, in this case the method record.store() does not update, it always insert even you have the id setted.
For now I am implementing my own saveOrUpdate, checking by the record id.