Hi!

I have a question regarding updating and inserting.

The AbstractRecord class marks every field as changed for which a 
setValue() was invoked. Only for key fields an equals() check is performed?
I wonder why that is.

If I call a setter and the new value is equal to the value read as original 
from the database, then the record in fact hasn't changed and an update is 
unnecessary, no?
We're doing synchronization work, and it would be very easy to just push 
the new values into the original record read from database, and then call 
changed() to see if it has actually changed or just call update() and let 
jOOQ decide whether to update or not. The setValue() method would be such a 
nice and central point to handle this, instead of iterating over the values 
and comparing them "manually".

Secondly, we run into a NullPointerException.

We're inserting into an Oracle database using a simple view. The view sits 
1:1 on top of a single table. We're calling DSLContext#newRecord() to get a 
new record created for that view. Nothing fancy.
The record provides an insert() method. But when we call the insert() 
method, we get:

.....
Caused by: 
*java.lang.NullPointerException*       at 
org.jooq.impl.TableRecordImpl.getReturning(*TableRecordImpl.java:315*)
       at org.jooq.impl.TableRecordImpl.storeInsert0(
*TableRecordImpl.java:171*)
       at org.jooq.impl.TableRecordImpl$1.operate(*TableRecordImpl.java:141*
)
       at org.jooq.impl.RecordDelegate.operate(*RecordDelegate.java:123*)
       at org.jooq.impl.TableRecordImpl.storeInsert(
*TableRecordImpl.java:137*)
       at org.jooq.impl.TableRecordImpl.insert(*TableRecordImpl.java:130*)
       at org.jooq.impl.TableRecordImpl.insert(*TableRecordImpl.java:125*)
       at .... .UserCreationProvider$1.run(*UserCreationProvider.java:180*)
       at org.jooq.impl.DefaultDSLContext$1.run(*DefaultDSLContext.java:352*
)
       at org.jooq.impl.DefaultDSLContext$1.run(*DefaultDSLContext.java:349*
)
       at org.jooq.impl.DefaultDSLContext.transactionResult(
*DefaultDSLContext.java:330*)
       at org.jooq.impl.DefaultDSLContext.transaction(
*DefaultDSLContext.java:349*)
       at .... .UserCreationProvider.createUser(
*UserCreationProvider.java:210*)


It seems that the record tries to add the key fields to a returning clause. 
Since a view doesn't have primary keys, getPrimaryKey() most like returns 
null and the insert() statements runs into the NPE.

For now we added a hack (put the jOOQ internal flag that switches off 
returning clauses into the jOOQ configuration), but that's probably not the 
way it should be. 
I understand that a record on a view doesn't have an update method (because 
of a lack of primary keys), and that we need to call 
create.executeUpdate(). But for inserting, no such method exists as far as 
I can tell and inserting on a view should be possible using a record, IMHO.

Regards,

Sascha

-- 
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/d/optout.

Reply via email to