使用Eclipse Indigo中的Hibernate工具进行逆向工程

时间:2011-09-17 16:02:32

标签: java eclipse sql-server-2008 hibernate hibernate-tools

我使用Eclipse Indigo和插件Hibernate Tools(JBoss by red hat)进行数据库连接我使用Microsoft SQL Server 2008 JDBC Driver。

当我尝试使用逆向工程工具(hibernate代码生成配置工具)基于数据库表生成类时,我得到“Serializable”类型字段而不是“string”类型字段。

import java.io.Serializable;

/**
* Customers generated by hbm2java
*/
public class Customers implements java.io.Serializable {

   private Serializable customerId;
   private Serializable companyName;
   private Serializable contactName;
   private Serializable contactTitle;
   private Serializable address;
   private Serializable city;
   private Serializable region;
   private Serializable postalCode;
   private Serializable country;
   private Serializable phone;
   private Serializable fax;

   public Customers() {
   }

   public Customers(Serializable customerId, Serializable companyName) {
      this.customerId = customerId;
      this.companyName = companyName;
   }

   public Customers(Serializable customerId, Serializable companyName,
         Serializable contactName, Serializable contactTitle,
         Serializable address, Serializable city, Serializable region,
         Serializable postalCode, Serializable country, Serializable phone,
         Serializable fax) {
      this.customerId = customerId;
      this.companyName = companyName;
      this.contactName = contactName;
      this.contactTitle = contactTitle;
      this.address = address;
      this.city = city;
      this.region = region;
      this.postalCode = postalCode;
      this.country = country;
      this.phone = phone;
      this.fax = fax;
   }

   public Serializable getCustomerId() {
      return this.customerId;
   }

   public void setCustomerId(Serializable customerId) {
      this.customerId = customerId;
   }

   public Serializable getCompanyName() {
      return this.companyName;
   }

   public void setCompanyName(Serializable companyName) {
      this.companyName = companyName;
   }

   public Serializable getContactName() {
      return this.contactName;
   }

   public void setContactName(Serializable contactName) {
      this.contactName = contactName;
   }

   public Serializable getContactTitle() {
      return this.contactTitle;
   }

   public void setContactTitle(Serializable contactTitle) {
      this.contactTitle = contactTitle;
   }

   public Serializable getAddress() {
      return this.address;
   }

   public void setAddress(Serializable address) {
      this.address = address;
   }

   public Serializable getCity() {
      return this.city;
   }

   public void setCity(Serializable city) {
      this.city = city;
   }

   public Serializable getRegion() {
      return this.region;
   }

   public void setRegion(Serializable region) {
      this.region = region;
   }

   public Serializable getPostalCode() {
      return this.postalCode;
   }

   public void setPostalCode(Serializable postalCode) {
      this.postalCode = postalCode;
   }

   public Serializable getCountry() {
      return this.country;
   }

   public void setCountry(Serializable country) {
      this.country = country;
   }

   public Serializable getPhone() {
      return this.phone;
   }

   public void setPhone(Serializable phone) {
      this.phone = phone;
   }

   public Serializable getFax() {
      return this.fax;
   }

   public void setFax(Serializable fax) {
      this.fax = fax;
   }

}

2 个答案:

答案 0 :(得分:0)

你需要编辑“hibernate.reveng.xml” 并将JDBC字段映射到Hibernate类型,如

<type-mapping>
    <sql-type jdbc-type="NUMERIC" precision='20' scale="0" hibernate-type="Long" />
</type-mapping>

另外,为了得到更具体的答案,只需指定客户表的数据库表结构。

希望这有帮助。

答案 1 :(得分:0)

在类型映射元素之后添加 hibernate.reveng.xml

**<type-mapping>
  <sql-type jdbc-type="NVARCHAR" hibernate-type="string"/>
  <sql-type jdbc-type="VARCHAR" hibernate-type="string"/>
</type-mapping>**