Hi All
For a while i'm using the GenericEnumUserType to map Enums:
http://www.hibernate.org/272.html
Now i have a problem with "null" values! My Enum looks like that:
Code:
public enum KursArt implements GenericEnum {
/**
* Minimalbedingungen nicht erreicht
*/
MINIMALBEDINGUNGEN_NICHT_ERREICHT(0, "LabelKursArtMinimalbedingungenNichtErreicht"),
/**
* Jahrekurs
*/
JAHRESKURS(1, "LabelJahreskurs"),
/**
* Saisonkurs
*/
SAISONKURS(2, "LabelSaisonkurs"),
/**
* Halber Saisonkurs, resp. Schnupperkurs.
*/
HALBER_SAISONKURS(3, "LabelHalberSaisonkurs");
private final Integer value;
private final String propertyKey;
private KursArt(Integer value, String label) {
this.value = value;
this.propertyKey = label;
}
/**
* @return
*/
public Integer getValue() {
return value;
}
/**
* @return
*/
public int intValue() {
return value.intValue();
}
/**
* Label der Enum
*
* @return
*/
public String getPropertyKey() {
return propertyKey;
}
/**
* @param value
* @return
*/
public static KursArt getInstanceByValue(Integer value) {
switch (value) {
case 0:
return MINIMALBEDINGUNGEN_NICHT_ERREICHT;
case 1:
return JAHRESKURS;
case 2:
return SAISONKURS;
case 3:
return HALBER_SAISONKURS;
default:
return null;
}
}
So in the Database is saved "null" and if hibernate maps the enumUyterType to my model it will return 0. So even if null is saved i get the Enum "MINIMALBEDINGUNGEN_NICHT_ERREICHT;" .
This is my mapping:
Code:
@TypeDef(name = "KursArt", typeClass = GenericEnumUserType.class, parameters = {
@Parameter(name = "enumClass", value = "najsre7.model.immutable.kurs.KursArt"),
@Parameter(name = "identifierMethod", value = "getValue"),
@Parameter(name = "valueOfMethod", value = "getInstanceByValue") })
/**
* @return kursArt
*/
@Type(type = "KursArt")
@Column(name = "SIPAR1", unique = false, nullable = true, insertable = true, updatable = true, precision = 5, scale = 0)
public KursArt getKursArt() {
return this.kursArt;
}
Does somebody know how to handle that??
Kind Regards
Angela