Hi Marcel,

The SQL DSL can't do that for you, but you can turn any POJO into a Record
using Record.from() or DSLContext.newRecord(...). You can then use
.insertInto(table).set(record). There's a RecordUnmapper SPI that governs
how to "unmap" POJOs into records, with a DefaultRecordUnmapper
implementation that works just like the DefaultRecordMapper in the other
way. Use this SPI in case you need to override the defaults.

Note, I always point out the benefits of using the code generator to folks
who don't:
https://blog.jooq.org/why-you-should-use-jooq-with-code-generation/

The main reason not to use the code generator is because the schema is
dynamic. If it isn't, you'll get tons of benefits from providing type
information to jOOQ (and work around tons of problems).

I hope this helps,
Lukas

On Mon, Mar 18, 2024 at 7:48 AM Marcel Overdijk <[email protected]>
wrote:

> I'm currently using JDBI on a project with a DAO like:
>
> @SqlBatch("insert_continent")
> fun insertContinents(@BindBean continents: List<Continent>)
>
> Note this uses the @BindBean to automatically bind bean properties to sql
> statements.
>
> E.g. the insert_continent sql file contains:
>
> INSERT INTO continent
> ( id
> , code
> , name
> )
> VALUES
> ( :id
> , :code
> , :name
> );
>
> and the bean is Java class like:
>
> public class Continent implements Serializable {
>
>     private String id;
>     private String code;
>     private String name;
>
> *    // getters + setters*
> *}*
>
> Now with jOOQ I want to do something similar, e..g having an insert like:
>
> val continent = .. // some continent
> val query = ctx
>     .insertInto(
>         table("continent"),
>         field("id"),
>         field("code"))
>         field("name"))
>     .values(
>         continent.id,
>         continent.code,
>         continent.name
>     )
>
> But then instead of access all properties by hand, just bind the bean.
>
> Would that be possible with jOOQ?
>
> Note: I do not want to use code generation for this.
> Also the Continent class is provided and cannot be changed.
>
>
> Thanks,
> Marcel
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "jOOQ User Group" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jooq-user/6eca1697-beef-4c63-921a-757cdcf0d8a7n%40googlegroups.com
> <https://groups.google.com/d/msgid/jooq-user/6eca1697-beef-4c63-921a-757cdcf0d8a7n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups "jOOQ 
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jooq-user/CAB4ELO5JqTBn1hKXcMVrCzHcFqodY%3D1zF0Xub6XW0J-ReAx_yg%40mail.gmail.com.

Reply via email to