实现效果如下:
- package com.fsti.ssh.entity.hibernate;
- // Generated 2013-6-21 18:10:59 by Hibernate Tools 3.4.0.CR1
- import java.math.BigDecimal;
- import java.util.Date;
- import java.util.LinkedHashMap;
- import java.util.Map;
- /**
- * TSsh generated by hbm2java
- */
- public class TSsh implements java.io.Serializable {
- /**
- * 主键-seq_ssh.
- */
- private String id;
- /**
- * 名称.
- */
- private String name;
- /**
- * 创建时间.
- */
- private Date createDate;
- /**
- * 更新时间.
- */
- private Date updateDate;
- /**
- * 类型;1:普通;2:特殊.
- */
- private String type;
- /**
- * 总数.
- */
- private BigDecimal count;
- public TSsh() {
- }
- public TSsh(String id) {
- this.id = id;
- }
- public TSsh(String id, String name, Date createDate, Date updateDate,
- String type, BigDecimal count) {
- this.id = id;
- this.name = name;
- this.createDate = createDate;
- this.updateDate = updateDate;
- this.type = type;
- this.count = count;
- }
- public static Map<String, String> relation = new LinkedHashMap<String, String>();
- static {
- relation.put("id", "主键-seq_ssh");
- relation.put("name", "名称");
- relation.put("createDate", "创建时间");
- relation.put("updateDate", "更新时间");
- relation.put("type", "类型;1:普通;2:特殊");
- relation.put("count", "总数");
- }
- public String getId() {
- return this.id;
- }
- public void setId(String id) {
- this.id = id;
- }
- public String getName() {
- return this.name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public Date getCreateDate() {
- return this.createDate;
- }
- public void setCreateDate(Date createDate) {
- this.createDate = createDate;
- }
- public Date getUpdateDate() {
- return this.updateDate;
- }
- public void setUpdateDate(Date updateDate) {
- this.updateDate = updateDate;
- }
- public String getType() {
- return this.type;
- }
- public void setType(String type) {
- this.type = type;
- }
- public BigDecimal getCount() {
- return this.count;
- }
- public void setCount(BigDecimal count) {
- this.count = count;
- }
- /**
- * toString
- *
- * @return String
- */
- @Override
- public String toString() {
- StringBuffer buffer = new StringBuffer();
- buffer.append(getClass().getName()).append("@")
- .append(Integer.toHexString(hashCode())).append(" [");
- buffer.append("]");
- return buffer.toString();
- }
- }
- <?xml version="1.0"?>
- <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
- "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
- <!-- Generated 2013-6-21 18:10:59 by Hibernate Tools 3.4.0.CR1 -->
- <hibernate-mapping>
- <class name="com.fsti.ssh.entity.hibernate.TSsh" table="T_SSH">
- <comment>演示表</comment>
- <id name="id" type="string">
- <column name="ID" length="40" />
- <generator class="assigned" />
- </id>
- <property name="name" type="string">
- <column name="NAME" length="500">
- <comment>名称</comment>
- </column>
- </property>
- <property name="createDate" type="date">
- <column name="CREATE_DATE" length="7">
- <comment>创建时间</comment>
- </column>
- </property>
- <property name="updateDate" type="date">
- <column name="UPDATE_DATE" length="7">
- <comment>更新时间</comment>
- </column>
- </property>
- <property name="type" type="string">
- <column name="TYPE" length="1">
- <comment>类型;1:普通;2:特殊</comment>
- </column>
- </property>
- <property name="count" type="big_decimal">
- <column name="COUNT" precision="22" scale="0">
- <comment>总数</comment>
- </column>
- </property>
- </class>
- </hibernate-mapping>
【1】用压缩软件打开 hibernate-tools-3.4.0.CR2.jar
【2】在pojo下,将PojoFileds.ftl 文件拖出压缩包,并进行如下修改:
- <#-- // Fields -->
- <#foreach field in pojo.getAllPropertiesIterator()>
- <#if pojo.getMetaAttribAsBool(field, "gen-property", true)>
- <#if pojo.hasMetaAttribute(field, "field-description")>
- /**
- ${pojo.getFieldJavaDoc(field, 0)}
- */
- </#if>
- <#foreach column in field.columnIterator><#if column.comment?exists && column.comment?trim?length!=0>
- /**
- * ${column.comment}.
- */</#if></#foreach>
- ${pojo.getFieldModifiers(field)} ${pojo.getJavaTypeName(field, jdk5)} ${field.name}
- <#if pojo.hasFieldInitializor(field, jdk5)> = ${pojo.getFieldInitialization(field, jdk5)}</#if>;
- </#if>
- </#foreach>
上面的代码,将实现在POJO类中,输出中文注释信息。
修改完成后,拖至压缩包中,即可实现重新打包操作。
【3】使用反编译工具,打开 org.hibernate.tool.hbm2x.TemplateProducer 类class文件,修改如下:
- // FileWriter fileWriter = null;
- Writer fileWriter = null;
- // fileWriter = new FileWriter(destination);
- fileWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(destination), "UTF-8"));
重新编译后,重新打包。
【4】打开org\hibernate\tool\hbm2x\jtidy.properties
在文件末尾添加如下代码:
- input-encoding=utf-8
- output-encoding=utf-8
【5】重新打包后,将新的Jar包,替换掉原有插件的Jar包。
比如笔者的插件包所在路径是:D:\eclipse\plugins\org.hibernate.eclipse.libs_3.6.0.Final-v20130327-1513-B111\lib\tools\hibernate-tools-3.4.0.CR2.jar;支持中文的hibernate-tools.jar下载
【6】重启eclipse,重新生成文件,即可实现带中文注释的配置文件和类代码。
注意:笔者的数据库环境是Oracle数据库。