我的hbm文件条目
<property name="rideType">
<column name="rideType" />
<type name="org.hibernate.type.EnumType">
<param name="enumClass">com.mcruiseon.common.Globals.RideType</param>
<param name="type">12</param>
</type>
</property>
异常
org.hibernate.MappingException: Unable to instantiate custom type: org.hibernate.type.EnumType
at org.hibernate.type.TypeFactory.custom(TypeFactory.java:218)
...
at com.mcruiseon.server.mCruiseOnServer.main(mCruiseOnServer.java:101)
Caused by: org.hibernate.HibernateException: Enum class not found
at org.hibernate.type.EnumType.setParameterValues(EnumType.java:239)
at org.hibernate.type.TypeFactory.injectParameters(TypeFactory.java:131)
... 17 more
Caused by: java.lang.ClassNotFoundException: com.mcruiseon.common.Globals.RideType
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at org.hibernate.type.EnumType.setParameterValues(EnumType.java:236)
... 19 more
代码
public class Globals {
...whole bunch of code...
public enum RideType {
PER_KM("PER_KM"), PER_HOUR_1("PER_HOUR_1"), PER_HOUR_2("PER_HOUR_2"), PER_HOUR_4(
"PER_HOUR_4"), PER_HOUR_8("PER_HOUR_8"), PER_HOUR_10(
"PER_HOUR_10"), PER_HOUR_12("PER_HOUR_12"), PER_HOUR_16(
"PER_HOUR_16");
private String description;
RideType(String description) {
this.description = description;
}
public String getDescription() {
return new String(description);
}
public static RideType getRideType(String value) {
if ("PER_KM".equalsIgnoreCase(value))
return PER_KM;
else if ("PER_HOUR_1".equalsIgnoreCase(value))
return PER_HOUR_1;
else if ("PER_HOUR_2".equalsIgnoreCase(value))
return PER_HOUR_2;
else if ("PER_HOUR_4".equalsIgnoreCase(value))
return PER_HOUR_4;
else if ("PER_HOUR_8".equalsIgnoreCase(value))
return PER_HOUR_8;
else if ("PER_HOUR_10".equalsIgnoreCase(value))
return PER_HOUR_10;
else if ("PER_HOUR_12".equalsIgnoreCase(value))
return PER_HOUR_12;
else if ("PER_HOUR_16".equalsIgnoreCase(value))
return PER_HOUR_16;
return null;
}
};
...whole bunch of code...
}
我已经尝试了所有的SO问题和答案,并且由于一些疯狂的原因它仍然抛出这个例外。我在这里缺少什么?
答案 0 :(得分:6)
这看起来像是在类(内部类枚举)中声明的枚举。如果这是真的。
更改:
<param name="enumClass">com.mcruiseon.common.Globals.RideType</param>
要:
<param name="enumClass">com.mcruiseon.common.Globals$RideType</param>