我为JPA实体使用枚举类型的一个字段:
@Enumerated(value=EnumType.STRING)
private Temperament temperament = Temperament.MINEUR_PUR;
我的枚举在我的实体内声明:
@Entity
public class Joueur implements Serializable {
.....
public enum Temperament{
MINEUR_PUR(30),
MINEUR(10),
NEUTRE(0),
RAIDEUR(-10),
RAIDEUR_PUR(-30);
private int temperament_prod_mines;
private Temperament(int temperament_prod_mines){
this.temperament_prod_mines = temperament_prod_mines;
}
public int getTemperament_prod_mines() {
return temperament_prod_mines;
}
public void setTemperament_prod_mines(int temperament_prod_mines) {
this.temperament_prod_mines = temperament_prod_mines;
}
}
}
它是可行的,但是当我将自己的枚举“外部化”到它自己的文件中时,它将不再起作用:
Caused by: Exception [EclipseLink-7151] (Eclipse Persistence Services – 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.ValidationException
Exception Description: The type [class com.sim.basics.enums.Temperament] for the attribute [temperament] on the entity class [class com.sim.entities.Joueur] is not a valid type for an enumerated mapping. The attribute must be defined as a Java enum.
但这只是复制/粘贴…
为什么会这样呢?
谢谢