Record mapping and custom jpa naming convention when using JPADatabase

12 views
Skip to first unread message

Jens Teglhus Møller

unread,
Oct 15, 2019, 3:58:40 AM10/15/19
to jOOQ User Group
Hi

As a follow up to some of my earlier questions regarding using SpringPhysicalNamingStrategy when generating using JPADatabase I'm now facing problems with record mapping my JPA classes.

When using the SpringPhysicalNamingStrategy a field named myField is mapped to column my_field which the DefaultRecordMapper will not match correctly (since I do not annotate using @Column(name="my_field")).

I tried to run the generator with jpaAnnotations=true so the Records get the jpa annotations but it looks like the mapper only looks for the annotations on the JPA classes.

Did anyone run into this and have a simple solution?

I thought about having locally maintained copies of DefaultRecordMapper/DefaultRecordUnmapper and their providers but I think the field name <-> column name conversion is pretty deeply buried in the code.

I could also just skip using the JPA classes and just use the Record classes, but I use lombok with @Accessor(chain=true) on my JPA classes and really miss chained setters on the Record classes, could I add that annotation myself with a costum Generator?

Just re-read my post and I can see it's a bit of a rambling but I still hope someone can suggest a way forward :-).

Best regards Jens

Lukas Eder

unread,
Oct 15, 2019, 5:41:47 AM10/15/19
to jOOQ User Group
Hi Jens,

Thanks for your message. In jOOQ, the @Column annotation is currently mandatory when you want to use DefaultRecordMapper to map to JPA annotated entities:

Do note that jOOQ is not a JPA compliant ORM. We did choose to re-use the @Column annotation because its semantics is already clear, but we do not support a variety of JPA annotations.

I could also just skip using the JPA classes and just use the Record classes, but I use lombok with @Accessor(chain=true) on my JPA classes and really miss chained setters on the Record classes, could I add that annotation myself with a costum Generator?  

You can  turn on the <fluentSetters/> flag in the code generator to make the setters fluent (returning "this"). You could try overriding JavaGenerator.generateRecordSetter to add additional annotations before the record setters... Not sure if that would  solve your problem.

Thanks
Lukas

--
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/a9141887-679e-4b0a-a7c2-5c8bc739d82d%40googlegroups.com.

Jens Teglhus Møller

unread,
Oct 15, 2019, 7:27:48 AM10/15/19
to jOOQ User Group
Hi Lukas

Thanks a lot. I think fluentSetters will work well for me, then I will just skip using JPA classes and just use the record classes.

The fluentSetters configuration option is missing from the manual, is seems like it got lost somewhere between 3.8.0 and 3.9.0 release (I did look for an option to generate fluent Records in the documentation but only for the latest version ;-).

There is a link to the xsd where it is specified though (http://www.jooq.org/xsd/jooq-codegen-3.12.0.xsd) but it is a bit hard to find.

Best regards Jens
To unsubscribe from this group and stop receiving emails from it, send an email to jooq...@googlegroups.com.

Lukas Eder

unread,
Oct 15, 2019, 10:58:12 AM10/15/19
to jOOQ User Group
Thanks for the hint. We'll look into documenting <fluentSetters/> in the manual as well:

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/27fec8bc-0929-4aa3-9c6f-46700e8c9766%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages