Add the ability to override how enums are mapped to the database.
See original GitHub issueUse case
I would like to able to map enums in Kotlin to integers in the database. The pre-existing databases that I am developing against (in SQL Server) have all the enum-like columns stored as integers often with a backing constraint table.
Describe the solution you’d like
I would like to be able to provide a custom DataType converter to map the enums but it does not work. The komapper-processor
is currently hard-coded to prioitise mapping enums to strings.
Versions
- Komapper: 1.0.0-RC1
- Kotlin: 1.6.21
- JVM: JDK 14.0.1
- JDBC Driver or R2DBC Driver: com.microsoft.sqlserver:mssql-jdbc:10.2.0.jre11
- Database: SQL Server 2014
- OS: Windows 10
Issue Analytics
- State:
- Created a year ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Hibernate Tips: How to map an Enum to a database column
In this Hibernate Tip, I show you how to map an Enum to a database column. You can choose between 2 standard options...
Read more >Mapping enums done right with @Convert in JPA 2.1
@Enumerated(EnumType.ORDINAL) (default) will map enum values using Enum.ordinal() . Basically first enumerated value will be mapped to 0 ...
Read more >Persisting Enums in JPA - Baeldung
A quick and practical guide to persisting enums in JPA. ... there's no convenient way to map Enum values to a database column....
Read more >Map enum in JPA with fixed values? - Stack Overflow
A simple solution is to use the Enumerated annotation with EnumType.ORDINAL: @Column(name = "RIGHT") @Enumerated(EnumType.ORDINAL) private Right right;.
Read more >Mapping Enums Done Right With @Convert in JPA 2.1 - DZone
@Enumerated(EnumType.STRING) is much safer because it stores string representation of enum . You can now safely add new values and move them ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
That’s a good idea, I’ve only just read up on value classes in the last week and haven’t used them anywhere yet. As a temporary fix, I can live without the exhaustive when(enum) and enum.values()
Thank you for the excellent work developing Komapper.
By the way, you can use value class instead of enum class. For example, the following code works with Komapper 1.0.0-RC1: