Hi Lukas,

On Friday, January 17, 2014 11:46:35 AM UTC-8, Lukas Eder wrote:
>
> Hi Sergei,
>
> 2014/1/17 sergivs <[email protected] <javascript:>>
>
>> Hi all,
>>
>> I'm just starting to use jOOQ and the first thing that I did was 
>> basically something like this (after creating bindings with the generation 
>> tool):
>>
>> MyRecord myRecord = dslContext.newRecord(MYTABLE, pojo);
>>
>> dslContext.execteInsert(myRecord);
>>
>> It's very convenient, but if the POJO does not have a field/getter 
>> method/annotation matching a given field, then the field simply will not be 
>> updated. Is there a way to force the insert/update to fail if a field 
>> cannot be found (other than making the field NOT NULL in the schema, which 
>> would be a hack and wouldn't work for updates, anyway)?
>>
>
> One thing that comes to mind is to implement a RecordListener, which can 
> listen on insertStart() events:
>
> http://www.jooq.org/doc/3.2/manual/sql-execution/crud-with-updatablerecords/crud-record-listener/
>
> I'm not sure if I correctly understood your requirements, but if you want 
> to check if any Record field value is NULL prior to executing an insert, 
> that would certainly be an option.
>  
>

This isn't exactly what I'm trying to do. Let me illustrate with an example.

Suppose there us a table called Balloons with the fields BalloonId (primary 
key), Size (null permitted), and Color (null permitted).

We create a class called Baloon that has methods getBalloonId(), getSize(), 
getColour(). Note the different spelling. Now, the colour may or may not be 
null, but if we create a record using DSLContext.newRecord(), the Color 
field will always be null and the error will go unnoticed until someone 
actually looks at the table data. Another example: we add a column called 
Shape but forget to add a corresponding method in the class.

Of course, if we coded every field and value pair by hand, for example, we 
wouldn't have these problems, but this flexibility doesn't have to be 
error-prone. There could be a policy or a flag that would determine whether 
there must be a corresponding field/method/annotation for every known field 
in the record that we are trying to generate from the POJO. It wouldn't be 
so difficult to add this, but I don't want to reinvent the wheel. Perhaps, 
this functionality is already there?

 

> There is a way of handling duplicate keys (update or ignore), as described 
>> here http://blog.jooq.org/tag/on-duplicate-key-update/, but it lacks the 
>> convenience and flexibility of DSLContext.executeInsert(Record).
>>
>> Is there a way to insert a record generated from a POJO dynamically as in 
>> my pseudocode above and handle the possible duplicate key?
>>
>
> Record.store() might do what you need. Or did you have something else in 
> mind?
>
> Cheers
> Lukas
>

I found UpdataleRecord.store() in the API. That will work for updates, 
which will be helpful. Is there a similar convenient way of doing an 
equivalent of INSERT ... ON DUPLICATE KEY IGNORE using a Record instance 
created from a POJO?

Thanks,

Sergei

-- 
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].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to