Hello,

I am using jOOQ for some time now, and I am very happy about it :)

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.

For instance:

POSTGRES: 

create type weekday as enum ( 'SUNDAY', 'MONDAY', 'TUESDAY', 'WEDNESDAY', 
'THURSDAY', 'FRIDAY', 'SATURDAY');

this results in: 

dwh=# select * from pg_enum where enumtypid='260085';
 enumtypid | enumsortorder | enumlabel 
-----------+---------------+-----------
    260085 |             1 | SUNDAY
    260085 |             2 | MONDAY
    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 


-- 
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to