I'm just stumbling from time to time over some problems, and this is one of them:
The order of the enum values generated in the enum classes is not the same as the order defined in the database.
create type weekday as enum ( 'SUNDAY', 'MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDAY', 'SATURDAY');
dwh=# select * from pg_enum where enumtypid='260085';
enumtypid | enumsortorder | enumlabel
-----------+---------------+-----------
260085 | 3 | TUESDAY
260085 | 4 | WEDNESDAY
260085 | 5 | THURSDAY
260085 | 6 | FRIDAY
260085 | 7 | SATURDAY
And this is the created enum:
public enum Weekday implements org.jooq.EnumType {
FRIDAY("FRIDAY"),
MONDAY("MONDAY"),
SATURDAY("SATURDAY"),
SUNDAY("SUNDAY"),
THURSDAY("THURSDAY"),
TUESDAY("TUESDAY"),
WEDNESDAY("WEDNESDAY"),
;
Apparently, the query used by jOOQ to create the enum is using "order by enumlabel asc",
not "order by enumsortorder". Therefore, the order of the enums are not in sync.
This is a problem as soon you try something like :
final static int SUNDAY = 1;
Weekday.values()[SUNDAY];
Sure, adding another constant to represent SUNDAY would be stupid, but if you use the
Calendar class, you want to map your Calendar.SUNDAY somehow to the Weekday.SUNDAY.
If they would be in the right order, Weekday.SUNDAY-1 would do the trick.
As they are not in the right order, I have to pull some dirty tricks. And I am using jOOQ to
get rid of dirty tricks and keep my database and my javacode "in sync".
Is there any chance that jOOQ will produce the enums in the right order, is there a flag or
configuration option, or is that something I will have to accept for the future ?
Best,
Patrik