insert into with dsl.newRecord

17 vues
Accéder directement au premier message non lu

nome cognome

non lue,
29 mars 2020, 16:24:3029/03/2020
à 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

non lue,
29 mars 2020, 17:13:0429/03/2020
à 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

non lue,
29 mars 2020, 18:04:5529/03/2020
à 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

non lue,
30 mars 2020, 03:15:2430/03/2020
à 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

non lue,
30 mars 2020, 03:51:3630/03/2020
à 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.
Répondre à tous
Répondre à l'auteur
Transférer
0 nouveau message