Grails 3 Unknown ordinal value 99 for enum class Book

Problem

Error message for grails:

Unknown ordinal value [99] for enum class [project.Book]

means that in database you have value - 99 which doesn't have correspondent match in the enum definition.

Solution

Sample enum in grails is:

package book

public enum BookCategory {

	DRAMA(0),
	FANTASY(1),
	ROMANCE(2),
	SCIFI(99),

	int id

	BookCategory(id) {
            this.id = id
        }
}

In this case in database you should store 4 - SCIFI and not 99. This is a common mistake done by newbies in grails.

So the solutions is to find the enum type - is it ordinal. And then to find the real values of the enumeration.

Similar error is: Grails Unknown name value [] for enum class [BookList]

Related Article