Spring Data and Jooq CodeGen

33 views
Skip to first unread message

Jonathan Burns

unread,
Oct 28, 2021, 1:19:55 PM10/28/21
to jOOQ User Group
I'm writing a simple 3-tier app using Spring Data:  https://github.com/jbburns/qcalendar

My idea was to have the following workflow:
- Data model is defined using liquibase -> this takes care of all DDL concerns
- Use this data model to generate Java code -> Jooq Codegen does this
- Integrate that generated code with Spring Data -> this will automagically create my REST API

Not that it matters here, but a further extension to this is:
- SpringDoc is used to generate an OpenAPI spec
- Gradle plugins are used to generate api for the front end

Basically the idea here is that the middle-tier is so simple that it can be mostly accomplished with codegen and Spring.

I currently have this entire workflow working in the aforementioned repo.


However, because the JPA Entities generated by Jooq do not include the relationship between each other, the results from the REST endpoint simply contain an ID (foreign key) to another entity as opposed to the Entity itself.  That would be resolved if there was a way to get Jooq to generate JPA 

My questions are:
- I'm not married to JPA... it was just the easiest way to do this.  Is anyone aware of a more direct integration between Jooq and Spring Data?
- Is there a way to get Jooq CodeGen to generate the JPA relationships?
For example, Jooq currently generates the following code:
public class Ao implements Serializable {

private static final long serialVersionUID = 1L;

private Integer id;
private Integer regionId;


However, I would like it to generate:
public class Ao implements Serializable {

private static final long serialVersionUID = 1L;

private Integer id;
@ManyToOne
@JoinColumn(name="region_id", nullable=false, updatable=false)
private Region region;




TIA

Lukas Eder

unread,
Oct 29, 2021, 2:24:20 AM10/29/21
to jOOQ User Group
Hi Jonathan,

jOOQ doesn't generate JPA entities. It can generate some JPA annotations to achieve some extent of interoperability, and to avoid re-inventing yet another set of our own annotations for annotation based mapping, but it was never the goal to generate actual entities.

I hope this helps,
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/b87c1e2d-d078-4c70-8891-06cc2017e80en%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages