humnate中的Java枚举

时间:2012-07-10 19:31:50

标签: java hibernate enums

我在MySQL表中有一个列,它有一个枚举变量:“questionTypes”

我将如何为此制作实体?

For String我这样做:

@Column(name = "explanation")

private String explanation

public String getExplanation() {
  return explanation;
}

public void setExplanation(String explanation) {
  this.explanation = explanation;
}

我应该为枚举做什么?

1 个答案:

答案 0 :(得分:5)

添加JPA的枚举注释(省略了getters / setters):

@Entity
class Answer {
   @Column(name = "explanation")
   private String explanation

   @Column(name = "questionType")
   @Enumerated(EnumType.STRING)
   private QuestionType type
}

其中QuestionType是常规Java枚举。