我正在尝试为表的枚举列映射实体属性。配置使用XML。但每当我运行代码时,它会在验证时抛出错误。
以下是我的映射 -
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.sample.employeemanager.pojo.Employee" table="employees">
<property name="gender">
<column name="gender" />
<type name="org.hibernate.type.EnumType">
<param name="enumClass">com.sample.employeemanager.pojo.support.Gender</param>
</type>
</property>
</class>
</hibernate-mapping>
我通过谷歌找到了这个解决方案。
我得到的错误如下:
Initial SessionFactory creation failed.
org.hibernate.HibernateException: Wrong column type in employees.employees for column gender. Found: enum, expected: integer
at org.hibernate.mapping.Table.validateColumns(Table.java:383)
at org.hibernate.cfg.Configuration.validateSchema(Configuration.java:1277)
at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:155)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:508)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1760)
at com.sample.employeemanager.common.HibernateUtil.buildSessionFactory(HibernateUtil.java:16)
at com.sample.employeemanager.common.HibernateUtil.<clinit>(HibernateUtil.java:9)
at com.sample.employeemanager.common.EmployeeManager.main(EmployeeManager.java:16)
性别枚举如下所示:
public enum Gender {
M, F
}
请注意,枚举是一个单独的源文件。
你知道可能出现什么问题吗?
答案 0 :(得分:0)
我认为您必须在类型标记内添加以下参数。
<param name="useNamed">true</param>
Thnaks, 阿米特库马尔