Eclipse 中的休眠 - 逆向工程

Posted

技术标签:

【中文标题】Eclipse 中的休眠 - 逆向工程【英文标题】:Hibernate in Eclipse - Reverse engineering 【发布时间】:2016-11-23 15:22:50 【问题描述】:

我正在尝试在 Eclipse IDE 中使用休眠,我已经成功地对 POJO 类进行了逆向工程。但是它显示会话工厂下的hibernate配置错误。

hibernate.cfg.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.password">1234</property>
    <property name="hibernate.connection.url">jdbc:mysql://localhost/customer</property>
    <property name="hibernate.connection.username">root</property>
    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>


    <mapping class="com.example.pojo.Customer"/>
    <mapping resource="com/example/pojo/Customer.hbm.xml"/>
</session-factory>
</hibernate-configuration>

hibernate.reveng.xml

<?xml version="1.0" encoding="UTF-8"?>

 <hibernate-reverse-engineering>
<table-filter match-catalog="customer" match-name="customer" />
<table catalog="customer" name="customer">
    <column name="id"></column>
    <column name="firstName"></column>
    <column name="cuscol"></column>
    <column name="lastName"></column>
    <column name="birthDate"></column>
    <column name="email"></column>
</table>
</hibernate-reverse-engineering>

客户波乔

public class Customer implements java.io.Serializable 

private int id;
private String firstName;
private String cuscol;
private String lastName;
private Date birthDate;
private String email;

public Customer() 


public Customer(int id) 
    this.id = id;


public Customer(int id, String firstName, String cuscol, String lastName, Date birthDate, String email) 
    this.id = id;
    this.firstName = firstName;
    this.cuscol = cuscol;
    this.lastName = lastName;
    this.birthDate = birthDate;
    this.email = email;


public int getId() 
    return this.id;


public void setId(int id) 
    this.id = id;


public String getFirstName() 
    return this.firstName;


public void setFirstName(String firstName) 
    this.firstName = firstName;


public String getCuscol() 
    return this.cuscol;


public void setCuscol(String cuscol) 
    this.cuscol = cuscol;


public String getLastName() 
    return this.lastName;


public void setLastName(String lastName) 
    this.lastName = lastName;


public Date getBirthDate() 
    return this.birthDate;


public void setBirthDate(Date birthDate) 
    this.birthDate = birthDate;


public String getEmail() 
    return this.email;


public void setEmail(String email) 
    this.email = email;



客户.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD   3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<!-- Generated Jul 20, 2016 4:45:13 PM by Hibernate Tools 4.0.0 -->
<hibernate-mapping>
<class name="Customer" table="customer" catalog="customer">
    <id name="id" type="int">
        <column name="id" />
        <generator class="assigned" />
    </id>
    <property name="firstName" type="string">
        <column name="firstName" length="45" />
    </property>
    <property name="cuscol" type="string">
        <column name="cuscol" length="45" />
    </property>
    <property name="lastName" type="string">
        <column name="lastName" length="45" />
    </property>
    <property name="birthDate" type="date">
        <column name="birthDate" length="10" />
    </property>
    <property name="email" type="string">
        <column name="email" length="45" />
    </property>
</class>
</hibernate-mapping>

【问题讨论】:

哎呀它在那里..sory 映射资源和映射类是否需要同时存在于同一个 Pojo 中?它可能不会抛出错误..但看起来不合适 【参考方案1】:

像这样更新 customer.hbm.xml 中的映射条目 -

<class="com.example.pojo.Customer" table= "customer"/>

【讨论】:

属性“table”无效

以上是关于Eclipse 中的休眠 - 逆向工程的主要内容,如果未能解决你的问题,请参考以下文章

如何将Mysql中的位类型映射到休眠?

如何使用休眠进行逆向工程以获取映射的超类

使用休眠和弹簧更新

eclipse 在部署的时候:eclipse中的一个工程,部署时在tomcat下出现有两个工程名称

无法在eclipse中保护代码免受逆向工程

如何使用Eclipse打开已有工程