Distributed SQL Tips: Java to PostgreSQL Enums Conversion

preview_player
Показать описание
With enums, we can enforce data integrity in a human-readable format. As a result, it’s unsurprising that this data type is natively supported in Java, PostgreSQL, and YugabyteDB. However, the conversion between Java and PostgreSQL enums doesn’t work out of the box.

The video shows a generic way of handling the Java and PostgreSQL enums conversion. The approach works for plain JDBC APIs and popular ORM frameworks such as Spring Data, Hibernate, Quarkus, and Micronaut.

Curious to learn more? Check out the following article:

DISCOVER MORE IN OUR DISTRIBUTED SQL TIPS FOR JAVA SERIES:

Video chapters:
0:00 Introduction
0:41 Test Overview
1:39 Testing enums on the database end
2:38 Passing Java enum as a String to YugabyteDB
5:00 Creating the cast operator
5:40 Repeating the test
6:37 Summary

About Yugabyte: YugabyteDB is an open source, high-performance distributed SQL database built for your mission-critical applications. It is PostgreSQL compatible, cloud native, and runs on any public or hybrid cloud.

RESOURCES:

COMMUNITY:

Рекомендации по теме
Комментарии
Автор

I was thinking of trying this for a "Market" where you have a lot of different articles to buy (at least 10-12 types) but I didn't know I could create a SQL type with it. I thought about declaring the name of the article type in a constructor like a String and then calling it through a method but this seems much easier. Thanks a lot.

MetAlan
Автор

Than you sir, tried out other solutions but they didn't work, this one saved me!

striker