close

[Solved] Error while fetching enum value from database: No enum constant, nested exception is java.lang.IllegalArgumentException

Hello Guys, How are you all? Hope You all Are Fine. Today I am facing the following error Error while fetching enum value from database: No enum constant, nested exception is java.lang.IllegalArgumentException in Java. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Error while fetching enum value from database: No enum constant, nested exception is java.lang.IllegalArgumentException Error Occurs?

Today I am facing the following error Error while fetching enum value from database: No enum constant, nested exception is java.lang.IllegalArgumentException in Java.

How To Solve Error while fetching enum value from database: No enum constant, nested exception is java.lang.IllegalArgumentException Error ?

  1. How To Solve Error while fetching enum value from database: No enum constant, nested exception is java.lang.IllegalArgumentException Error ?

    To Solve Error while fetching enum value from database: No enum constant, nested exception is java.lang.IllegalArgumentException Error You should have UPVOTE or DOWNVOTE as values in the db. Because JPA will look for enum with the same name.

  2. Error while fetching enum value from database: No enum constant, nested exception is java.lang.IllegalArgumentException

    To Solve Error while fetching enum value from database: No enum constant, nested exception is java.lang.IllegalArgumentException Error You should have UPVOTE or DOWNVOTE as values in the db. Because JPA will look for enum with the same name.

Solution 1

You should have UPVOTE or DOWNVOTE as values in the db. Because JPA will look for enum with the same name.

If you had already stored the value in db, delete it and recreate it via your application.

Solution 2

When you create a enum, the enum name(UPVOTE(“up”), DOWNVOTE(“down”)) gets into database, make sure it’s in caps in table. the value is only at the service level, I suggest, avoid adding value string unless required.

try this version of getVoteType

public static VoteType getVoteType(final String value) {
    for (final VoteType voteType : values()) {
        if (voteType.value.equalsIgnoreCase(value)) {
            return voteType;
        }
    }
    final String message = "Unknown VoteType " + value + ", allowed values are " + Arrays.toString(values());
    throw new Excetion(message);
}

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read