users@glassfish.java.net

Re: use of enum class in entity

From: <glassfish_at_javadesktop.org>
Date: Mon, 27 Jul 2009 23:57:59 PDT

It can't be done. As far as I can tell, the ordinal is generated by the compiler.

The work around would be as follows:

public enum MQAEnumState {

ACTIVE(1),
IN_ACTIVE(10),
NEW_USER(100);

private final int number;

private MQAEnumState(int number)
{
this.number = number;
}

public int getNumber()
{
return number;
}

}

All this does is add another field to the class, so you can access the number you wanted in your code.

But changing the ordinal itself? Can't be done. Note that the method is declared as 'final' in the Enum class, so there's no overriding it either.

Having looked at the @Enumeration annotation, I suspect that this won't actually work for you, but there we go.
[Message sent by forum member 'ipsi' (ipsi)]

http://forums.java.net/jive/thread.jspa?messageID=357828