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

发布于 2024-12-05 03:38:33 字数 3340 浏览 2 评论 0原文

我使用 Eclipse Indigo 和插件 Hibernate Tools(JBoss by red hat)进行数据库连接我使用 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;
   }

}

I use Eclipse Indigo with plugin Hibernate Tools (JBoss by red hat) for database connection I use Microsoft SQL Server 2008 JDBC Driver.

When I try to use Reverse Engineering tool (hibernate code generation configuration tool) to generate class based on database table, instead of "string" type fields I get "Serializable" type fields.

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

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦开始←不甜 2024-12-12 03:38:34

添加到您的 hibernate.reveng.xml 以下类型映射元素中

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

add into yours hibernate.reveng.xml following type-mapping element

**<type-mapping>
  <sql-type jdbc-type="NVARCHAR" hibernate-type="string"/>
  <sql-type jdbc-type="VARCHAR" hibernate-type="string"/>
</type-mapping>**
卖梦商人 2024-12-12 03:38:33

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

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

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

希望这有帮助。

You need to edit "hibernate.reveng.xml"
And map the JDBC fields to the Hibernate Types like

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

Also to get more concrete answer just specify the Database Table Structure of Customer(s) Table.

Hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文