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

We Are Going To Discuss About Error while fetching enum value from database: No enum constant, nested exception is java.lang.IllegalArgumentException. So lets Start this Java Article.

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

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

    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.

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

    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 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.

Original Author Of This Content

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);
}

Original Author Of This Content

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

Siddharth

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment