我正在使用hibernate-entity-generator(maven插件)从数据库表生成实体类。
生成实体中的所有数据类型都是对象类型,如何让hibernate生成主要类型而不是对象类型?
例如,我有一个user_data_profile表(mysql):
+--------------------+------------+ | Field | Type | +--------------------+------------| | id | bigint(20) | | login_times | int(11) | | work_apply_times | int(11) | | work_done_times | int(11) | +--------------------+------------+
生成的实体类如下:
public class UserDataProfile {
private Long id;
private Integer loginTimes;
private Integer workApplyTimes;
private Integer workDoneTimes;
}
我真正想要的是:
public class UserDataProfile {
private long id;
private int loginTimes;
private int workApplyTimes;
private int workDoneTimes;
}
答案 0 :(得分:0)
最后我找到了解决方案,并在此处发布。 希望它可以帮助别人。
要使hibernate实体生成器生成主要类型而不是包装器对象,我们需要在“hibernate-reverse-engineering”配置文件中配置类型映射。例如:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering PUBLIC
"-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" >
<hibernate-reverse-engineering>
<schema-selection match-schema="user"/>
<!-- use type-mappings to mapping jdbc type and hibernate type -->
<type-mapping>
<sql-type jdbc-type="BIGINT" hibernate-type="long"/>
<sql-type jdbc-type="INTEGER" hibernate-type="int"/>
</type-mapping>
<table schema="user" name="user">
<primary-key>
<key-column name="id"/>
</primary-key>
</table>
</hibernate-reverse-engineering>