Java Hibernate with Negative Enums
I'm using Hibernate for JPA for persisting objects to my database. One class has four possible statuses that I want to represent with an enum, and I want to use a negative status for DELETED for consistency with previous classes:
However, Hibernate doesn't like this and is throwing an exception:
Is there a simple way to tell Hibernate to allow the negative Enum value? Or do I have to use non-negative values?
11 Replies
⌛
This post has been reserved for your question.
Hey @AgentMime! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
Just make it a user type. If you want Hibernate to use an enum automatically, it will just do the simplest and use their ordinal number.
Alternatively https://stackoverflow.com/a/41645518/10871900
Stack Overflow
Hibernate map enum by property value
I'm trying to do the following using Hibernate:
When an object is saved to the DB, it is saved as a the value of the enum's name property.
When an object is retrieved from the DB, the object reads...
What do you mean by "user" type?
....... New game: before you ask a question like this one you first assume it must have some meaning and you freaking google it
Fair enough lol
what a fun game 😂 - but beware the dangers of learning something on the way
💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.
This was a bit verbose but it works great, thanks!
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
Post Closed
This post has been closed by <@406648669748592650>.