EnumJavaTypeDescriptor.toOrdinal and fromOrdinal


I’m subclassing EnumJavaTypeDescriptor (i’m want to get the enum java.util.Month to start at 1 when persisted, so that JANUARY -> 1, …, DECEMBER -> 12) and the two methods toOrdinal and fromOrdinaldo not use the Type T of the class declaration (EnumJavaTypeDescriptor<T extends Enum>) but rather redefine their own type : public <E extends Enum> E fromOrdinal(Integer relationalForm) {

Is there a reason for that ?

(It do not prevent me from doing what i want, but it requires more typecasting that seems necessary)

It’s not clear what you are asking. You can create a new custom Type that saves the java.time.Month starting from 1 instead of 0, and you can achieve that via the EnumJavaTypeDescriptor.

Just use Month.of(int month) instead of getJavaType().getEnumConstants()[ relationalForm ] and Month.getValue instead of domainForm.ordinal().

You should contribute the new Type to the hibernate-types open-source project as it supports custom types for Year and YearMonth.

Sorry if my question was not clear.

Let me rephrase it : Why the signature of toOrdinal is

public <E extends Enum> Integer toOrdinal(E domainForm) {

and not

public Integer toOrdinal(T domainForm) {


Probably it should be changed to:

public T Integer toOrdinal(T domainForm) {
	if ( domainForm == null ) {
		return null;
	return domainForm.ordinal();

public T fromOrdinal(Integer relationalForm) {
	if ( relationalForm == null ) {
		return null;
	return T getJavaType().getEnumConstants()[ relationalForm ];

You should create a Jira issue for it.