Search code examples
javajooq

What's the recommend way of cloning a jOOQ Record object?


It seems like you can't create a copy constructor, you can't make it implement cloneable.

I was thinking of using reflection to iterate over every attribute on the child class but is there a better way?


Solution

  • It seems like you can't create a copy constructor, you can't make it implement cloneable.

    You can implement these things in the code generator easily yourself. In both cases, you will need to generate some custom code, and in the case of Cloneable, you will need to write a generator strategy (programmatic or configurative), which adds the Cloneable interface to all generated records.

    If you're not using generated records, or if you want to clone any arbitrary record, you can still use one of the many Record.into() methods, which copy record contents into a new type.