Custom Validator on Fields in Jooq Entities

8 views
Skip to first unread message

Charith Chowdary K P

unread,
Sep 11, 2019, 7:31:02 AM9/11/19
to jOOQ User Group
Hi,

Is it possible to add a hibernate validator or a custom validator to a specific column of a table using Jooq.
The entities are generated via CodeGen.

for ex. 

Is it possible to annotate that field with Validator functions.

Consider a "Book" Table. "Title" is a property of the Book Table.
Title is supposed to have only safeHtml. 

like e.g.

BookRecord.java 

@SafeHtml
public String setTitle(final String title)
{
}


Is there a way to do this via some settings in Codegen xml or any other way. Looking for some direction regarding this.

Thanks.

Lukas Eder

unread,
Sep 11, 2019, 7:48:42 AM9/11/19
to jOOQ User Group
Hi Charith,

Thank you very much for your message.

In jOOQ, the most appropriate way to implement this kind of functionality would be to use a custom data type converter, which converts your bind variables of some HTML type to a string, and back to that HTML type:

In my personal opinion, this would also be the best way to validate said string in Hibernate, instead of using a string type (raw data) to model HTML. Using semantic types, you can *always* guarantee that your HTML content implements the semantics of that type, and you do not rely on some external mechanism to attach to some lifecycle that is not really related to the type itself.

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/a0ce661d-4e2b-43f0-a95c-14976929277e%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages