There are two t_statuses and t_operators . In the first value (-1 - BANNED, 0 - OFFLINE, 1 - ONLINE) , in the second, the actual operators, whose status is the foreign key ( status_id ) on the first table. In java code, I instead of the entity class for statuses made enum:

 public enum OperatorStatus { BANNED(-1), OFFLINE(0), ONLINE(1); private int id; OperatorStatus(int id) { this.id = id; } public int getValue() { return id; } } 

The database has one entry with the status 0 - OFFLINE . If in the Operator class the status field is made the type Integer, then 0 is set to it. But, if I create a field of type OperatorStatus , its value becomes equal to BANNED , i.e. -one. What is the reason for this difference?

  • Show me how you create an instance of OperatorStatus - Leonid
  • Hibernate is engaged in it, for OperatorStatus only the summary with the indication of a column name is specified - carapuz

1 answer 1

when you create a field of type OperatorStatus , I think you assign a value with os.ordinal() equal to 0 - i.e. first of the list
int / Integer also set to zero upon initialization.
PS How do you declare a field of type OperatorStatus and you do not have a NullPointerException ?