How To Fetch One To Many Data Inside A MAP

10 views
Skip to first unread message

Debapriya Patra

unread,
Jul 18, 2021, 9:43:36 PMJul 18
to jOOQ User Group
Hi,

I have a table as follow.
+----------------+--------------+------+-----+-------------------+-----------------------------+
| Field          | Type         | Null | Key | Default           | Extra                       |
+----------------+--------------+------+-----+-------------------+-----------------------------+
| seq            | int(11)      | NO   | PRI | NULL              | auto_increment              |
| id             | varchar(36)  | NO   |     | NULL              |                             |
| edu_content_id | varchar(36)  | NO   | MUL | NULL              |                             |
| reason         | varchar(200) | NO   |     | NULL              |                             |
| media_type     | varchar(255) | NO   |     | NULL              |                             |
| file_name      | varchar(255) | NO   |     | NULL              |                             |
| revision       | int(1)       | NO   |     | 1                 |                             |
| description    | varchar(250) | NO   |     | NULL              |                             |
| comment        | varchar(250) | YES  |     | NULL              |                             |
| num_pages      | int(4)       | YES  |     | 0                 |                             |
| created_ts     | timestamp    | NO   |     | CURRENT_TIMESTAMP |                             |
| updated_ts     | timestamp    | NO   |     | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
+----------------+--------------+------+-----+-------------------+-----------------------------+

This table stores one-to-many relationship with the edu_content_id column value.
I wanted to send a list of edu_content_id and fetch a Map<String, List<EduContent>> values.

I was trying to see if I can use .intoGroups() function from Jooq but getting confused.

My query is basically as follows. I just need revision and created_ts and Map into EduContent entity. End of the day the Map key is edu_content_id and value is a List if EduContent which will only have revision and created_ts.

dsl.select(
EDU_REVISED_CONTENT.REVISION,
EDU_REVISED_CONTENT.CREATED_TS)
.from(EDU_REVISED_CONTENT)
.where(EDU_REVISED_CONTENT.EDU_CONTENT_ID.in(eduContentIds)).orderBy(EDU_REVISED_CONTENT.CREATED_TS.desc()).fetch();


Just wanted to know if this is possible by using a Jooq query.

Thanks In advance.

Thanks,
Deba

Lukas Eder

unread,
Jul 19, 2021, 10:17:58 AMJul 19
to jOOQ User Group
Yes this sounds like a perfect job for fetchGroups(). What's not working?

--
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/a3014437-2018-405d-ad50-a120db4b8967n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages