【问题标题】:Reverse Engineering with Hibernate Tools in Eclipse Indigo在 Eclipse Indigo 中使用 Hibernate 工具进行逆向工程
【发布时间】:2011-09-17 16:02:32
【问题描述】:

我使用带有插件 Hibernate Tools(红帽的 JBoss)的 Eclipse Indigo 进行数据库连接我使用 Microsoft SQL Server 2008 JDBC 驱动程序。

当我尝试使用逆向工程工具(休眠代码生成配置工具)基于数据库表生成类时,我得到的不是“字符串”类型字段,而是“可序列化”类型字段。

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;
   }

}

【问题讨论】:

  • 不清楚你的问题是什么。如果您提出问题,有人可能会为您提供帮助。
  • 我不是 java 程序员,但也许你可以编辑你的问题来解释为什么只做一个搜索并替换 Serializable -> String 是不够的?
  • 当然可以替换,我就是想知道为什么generator使用Serializable类型。
  • 好的,那是你的问题。似乎没有真正了解 java 的人回答过,所以不妨尝试编辑一下。

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


【解决方案1】:

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

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

还要获得更具体的答案,只需指定客户表的数据库表结构。

希望这会有所帮助。

【讨论】:

    【解决方案2】:

    添加到你的 hibernate.reveng.xml 跟随类型映射元素

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

    【讨论】:

      猜你喜欢
      • 2011-02-20
      • 1970-01-01
      • 2014-11-07
      • 2011-03-13
      • 2012-03-15
      • 2012-03-10
      • 2016-05-22
      • 2021-05-14
      • 1970-01-01
      相关资源
      最近更新 更多