How to use UpdateableRecord without code generation

23 views
Skip to first unread message

Max Kremer

unread,
Sep 11, 2019, 3:54:07 PM9/11/19
to jOOQ User Group
I'm trying to perform some simple CRUD operations with JPA annotated Pojos.

I've run into the need of returning the generated id (Identity columns) for records that are inserted. Seems that the best way to do this is with UpdateableRecord
 
To date we've been using  CustomRecord and its hasn't really come up


public class SpendEventRecord extends CustomRecord<SpendEventRecord> {

But I can't figure out how to create UpdatebleRecord instances based on my pojos.

Related: 

Knut Wannheden

unread,
Sep 12, 2019, 5:37:27 AM9/12/19
to jOOQ User Group
Hi Max,

Thank you for your message.

If you in the generator configuration haven't set <records>false</records>, then the jOOQ code generator should automatically be generating UpdatableRecordImpl subclasses for all your tables. You should then be able to use these classes instead of your CustomRecord subclasses.

I hope this answers your question.

Knut

Max Kremer

unread,
Sep 12, 2019, 10:02:12 AM9/12/19
to jOOQ User Group
Sorry I should've pointed out that I'm not using the code generator.

Knut Wannheden

unread,
Sep 12, 2019, 10:10:29 AM9/12/19
to jooq...@googlegroups.com
Hi Max,

On Thu, Sep 12, 2019 at 4:02 PM Max Kremer <mkr...@trialfire.com> wrote:
Sorry I should've pointed out that I'm not using the code generator.

I see. Just out of curiosity: Why not? Do you also write TableImpl subclasses by hand?

You could of course also have your classes extend UpdatableRecordImpl rather than CustomRecord in the same way they get generated by the code generator. For an (arbitrary) example see here: https://github.com/jOOQ/jOOQ/blob/master/jOOQ-examples/jOOQ-kotlin-example/src/main/java/org/jooq/example/db/h2/tables/records/AuthorRecord.java.

Hope this helps,
Knut

Max Kremer

unread,
Sep 12, 2019, 10:20:30 AM9/12/19
to jOOQ User Group
No specific reason other than we haven't really needed to.

Yes, we write our own TableImpl subclasses by hand but there are only 3-4 of them. Our application is mostly doing analytics and we rely on JOOQ as a DSL for building queries (creating reusable chunks of SQL and combining them, manipulating them etc...). So far JOOQ has been perfect for that. We haven't had the requirement to do typical CRUD operations on records/objects.... until now.
I looked at the UpdatableRecordImpl class but the internal docs say "This type is for JOOQ INTERNAL USE only. Do not reference directly"

Knut Wannheden

unread,
Sep 12, 2019, 10:30:23 AM9/12/19
to jooq...@googlegroups.com
Hi Max,

On Thu, Sep 12, 2019 at 4:20 PM Max Kremer <mkr...@trialfire.com> wrote:
No specific reason other than we haven't really needed to.

Yes, we write our own TableImpl subclasses by hand but there are only 3-4 of them. Our application is mostly doing analytics and we rely on JOOQ as a DSL for building queries (creating reusable chunks of SQL and combining them, manipulating them etc...). So far JOOQ has been perfect for that. We haven't had the requirement to do typical CRUD operations on records/objects.... until now.
I looked at the UpdatableRecordImpl class but the internal docs say "This type is for JOOQ INTERNAL USE only. Do not reference directly"

When upgrading to a new jOOQ version I would recommend that you do run the code generator and at least compare its output to your own hand-maintained classes.

The TableImpl class has the same disclaimer in the Javadoc and both classes are also annotated as @Internal. But extending either of these classes (like the code generator does) is legitimate. But please note that, since these are internal classes, the API could break in backwards incompatible ways in a future minor release. This is not a problem if you are using the code generator, as its API remains backwards compatible and it will always generate classes matching TableImpl and UpdatableRecordImpl.

Regards,
Knut

Max Kremer

unread,
Sep 12, 2019, 10:33:03 AM9/12/19
to jooq...@googlegroups.com
Ok Thanks Knut, I'll explore the code generator.
Regards,

Max Kremer

twitter: @maxtrialfire
skype: maxkremer




--
You received this message because you are subscribed to a topic in the Google Groups "jOOQ User Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jooq-user/CYnkebb9inc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jooq-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jooq-user/CAFx%3DKgfBYjnSy-BO-aAYsCia_KeL2UYofEP2rqwQ7ShbtZYkZg%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages