hello
i have the same problem! always getting the error:
java.lang.IllegalArgumentException: object is not an instance of declaring class
did you find a solutions??
my method looks like that:
Code:
public Object nullSafeGet(ResultSet rs, String[] names, Object owner)
throws HibernateException, SQLException {
Object identifier=type.get(rs, names[0]);
try {
return valueOfMethod.invoke(enumClass, new Object [] {identifier});
}
catch(Exception exception) {
throw new HibernateException(
"Exception while invoking valueOfMethod of enumeration class: ", exception);
}
}
My Enum class:
Code:
public enum UnterrichtsDauerEnum implements Serializable {
Unknown(0), GROESSER_GLEICH_60(1), GROESSER_GLEICH_90(2);
int value;
private UnterrichtsDauerEnum(int value) {
this.value = value;
}
/**
* @return
*/
public int toInt() {
return value;
}
/**
* @param value
* @return
*/
public UnterrichtsDauerEnum fromInt(int value) {
switch (value) {
case 1:
return GROESSER_GLEICH_60;
case 2:
return GROESSER_GLEICH_90;
default:
return Unknown;
}
}
}
And here the parts of my mapping file:
Code:
<typedef name="UnterrichtsDauerEnum" class="najsre7.dao.hibernate.userType.immutable.GenericEnumUserType">
<param name="enumClass">najsre7.model.immutable.kurs.UnterrichtsDauerEnum</param>
<param name="identifierMethod">toInt</param>
<param name="valueOfMethod">fromInt</param>
</typedef>
<subclass name="najsre7.model.KursNutzergruppe1" discriminator-value="1">
<property name="kursArt" type="najsre7.dao.hibernate.userType.immutable.kurs.KursArtUT">
<meta attribute="use-in-tostring">true</meta>
<meta attribute="use-in-equals">true</meta>
<column name="SIPAR1" precision="5" scale="0" not-null="true" />
</property>
<property name="unterrichtsDauer" type="UnterrichtsDauerEnum">
<meta attribute="use-in-tostring">true</meta>
<meta attribute="use-in-equals">true</meta>
<column name="SIPAR2" precision="5" scale="0" />
</property>
<property name="gruppenGroesse" type="najsre7.dao.hibernate.userType.immutable.kurs.GruppenGroesseUT">
<meta attribute="use-in-tostring">true</meta>
<meta attribute="use-in-equals">true</meta>
<column name="SIPAR3" precision="5" scale="0" not-null="true" />
</property>
//more
angela