insert into with dsl.newRecord

17 views
Skip to first unread message

nome cognome

unread,
Mar 29, 2020, 4:24:30 PM3/29/20
to jOOQ User Group
Hi everyone,
i have a question, i want to put data in db using:

public Table<?>  = DSL.table(DSL.name(schema, Batch.BATCH.getName()));

BatchRecord br = dsl.newRecord(tablesFields.batchTable , batchPOJO);

dsl.insertInto(Batch.BATCH).set(br).onDuplicateKeyUpdate().set(br).execute(); 


but i have some problem  with dsl.newRecord


how i do to resolve?

thanks

Giuseppe

Rob Sargent

unread,
Mar 29, 2020, 5:13:04 PM3/29/20
to jooq...@googlegroups.com
And exactly what problem are you having?

-- 
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 jooq-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jooq-user/5853ba15-4919-4939-90b3-bdcb849274d9%40googlegroups.com.

iz8...@gmail.com

unread,
Mar 29, 2020, 6:04:55 PM3/29/20
to jooq...@googlegroups.com
Sorry for mistake my code are:

BatchRecord br = (BatchRecord) dsl.newRecord(DSL.table(DSL.name("schema", Batch.BATCH.getName())) , batch);

dsl.insertInto(DSL.table(DSL.name("schema", Batch.BATCH.getName()))).set(br).onDuplicateKeyUpdate().set(br).execute(); 


the error are:

java.lang.ClassCastException: class org.jooq.impl.RecordImpl cannot be cast to class it.ieo.dao.jooq.codegen.dc1.tables.records.BatchRecord (org.jooq.impl.RecordImpl and it.ieo.dao.jooq.codegen.dc1.tables.records.BatchRecord are in unnamed module of loader 'app')


Lukas Eder

unread,
Mar 30, 2020, 3:15:24 AM3/30/20
to jOOQ User Group
Hi Giuseppe

A lot of methods in jOOQ depend on the meta data of your tables / fields. Ideally, you will be using the code generator, which produces this meta data for you. If you use the plain SQL API, there is no way how jOOQ could possibly know what fields are contained in a given table, so your call to DSLContext::newRecord cannot work this way, because jOOQ doesn't know what fields to associate values from your POJO with.

The error you're getting happens earlier. You're unsafely casting a generic org.jooq.Record type to a BatchRecord type, which you probably got from the code generator.

But why are you using the plain SQL API in the first place? Just pass the BATCH table reference to dsl.newRecords(BATCH, batchPOJO). Perhaps you intended for the schema name to be changed dynamically from the generated schema to something else, at runtime? We have an entire feature for that:

I hope this helps,
Lukas 

iz8...@gmail.com

unread,
Mar 30, 2020, 3:51:36 AM3/30/20
to jooq...@googlegroups.com
Perhaps you intended for the schema name to be changed dynamically from the generated schema to something else, at runtime?

Yes, because i need a schema for each admin.

To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+unsubscribe@googlegroups.com.

--
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 jooq-user+unsubscribe@googlegroups.com.

--
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 jooq-user+unsubscribe@googlegroups.com.

--
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 jooq-user+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jooq-user/CAB4ELO5XCcYA%3DAFQXYPi5eBpQEHbjy8TXYizDFGU2QOStKB2Pw%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages