I want to map Enum's value with hibernate for fetching data from DB.
In DB column **EASE_RATING** is number[1]. I'm able to save data in DB as Numeric.
But When I retrieve data by Criteria.list() I get easeRating=Two instead of easeRating=2.
My question is How can I get Data in form of Ordinal Or Enums's Value.
public enum Rating {
Zero(0), // [No use] Taken Zero B'Coz Ordinal starts with 0
One(1),
...
Five(5);
private final int value;
Rating(int value){
this.value = value;
}
public int getValue(){
return this.value;
}
public static Rating getRating(int x) {
switch(x) {
case 1: return One; ...
case 5: return Five;
}
return One;
}
}
POJO:
@Enumerated(EnumType.ORDINAL)
@Column(name = "EASE_RATING", nullable = false)
private Rating easeRating;
UPDATE
I want this value in int[ordinal()] in Hibernate List(). I'm hitting DB through hibernate.
List<CustomerFeedback> result = criteria.list();
I can achieve value throgh **getValue()**
System.out.println(Rating.Five.getValue()); // 5
System.out.println(Rating.Five); // Five
System.out.println(Rating.Five.name()); // Five
But How would I get this in Hibernate list()
Rating.Two. You can call getValue() on this instance to get its value.