2016-02-13 44 views
0

我正在为一个学校项目首次使用Hibernate,我们正在为食品卡车构建一个类似Yelp的应用程序。但是,因为我首先创建了我的数据库模式,所以我使用Hibernate的逆向工程特性来生成Java类。但是,我无法让Hibernate按照我想要的方式生成Java类。这是我的hibernate.reveng.xml中文件无法使用Hibernate对java类进行逆向工程更改

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd"> 
<hibernate-reverse-engineering> 
    <schema-selection match-catalog="FoodTrucks"/> 
    <table-filter match-name="item"/> 
    <table-filter match-name="tags"/> 
    <table-filter match-name="truck"/> 
    <table-filter match-name="menu"/> 
    <table-filter match-name="tag_item_map" exclude="true"/> 
    <table-filter match-name="user"/> 
    <table-filter match-name="item_review"/> 
    <table-filter match-name="truck_review"/> 
    <table name="item"> 
     <column name="menu_id" exclude="true"></column> 
     <foreign-key constraint-name="item_review_ibfk_2"> 
      <many-to-one property="items"></many-to-one> 
     </foreign-key> 
     <foreign-key constraint-name="tag_item_map_ibfk_1"> 
      <set property="tags"></set> 
     </foreign-key> 
    </table> 
    <table name="menu"> 
     <column name="truck_id" exclude="true"></column> 
     <foreign-key constraint-name="item_ibfk_1"> 
      <many-to-one property="items"></many-to-one> 
     </foreign-key> 
    </table> 
    <table name="tags"> 
     <foreign-key constraint-name="tag_item_map_ibfk_2"> 
      <many-to-one property="items"></many-to-one> 
     </foreign-key> 
    </table> 
    <table name="truck"> 
     <foreign-key constraint-name="menu_ibfk_1"> 
      <many-to-one property="menus"></many-to-one> 
     </foreign-key> 
     <foreign-key constraint-name="truck_review_ibfk_2"> 
      <many-to-one property="reviews"></many-to-one> 
     </foreign-key> 
    </table> 
    <table name="user"> 
     <column name="pass_word" exclude="true"></column> 
     <foreign-key constraint-name="item_review_ibfk_1"> 
      <many-to-one property="itemReviews"></many-to-one> 
     </foreign-key> 
     <foreign-key constraint-name="truck_review_ibfk_1"> 
      <many-to-one property="truckReviews"></many-to-one> 
     </foreign-key> 
    </table> 
</hibernate-reverse-engineering> 

不过,我能得到它做正确的唯一的事情就是排除标签项目表。例如,这里是生成的Item类,没有getter和setter。

public class Item implements java.io.Serializable { 


    private Integer id; 
    private Menu items; 
    private String itemName; 
    private double price; 
    private Set itemReviews = new HashSet(0); 

    public Item() { 
    } 


    public Item(String itemName, double price) { 
     this.itemName = itemName; 
     this.price = price; 
    } 
    public Item(Menu items, String itemName, double price, Set itemReviews) { 
     this.items = items; 
     this.itemName = itemName; 
     this.price = price; 
     this.itemReviews = itemReviews; 
    } 

// getters and setters down here 
} 

我知道我在做一些错误的或不正确的事情,但我不知道是什么。另外,当我在初始生成后尝试生成代码时,出现错误消息“Hibernate配置失败,消息:resource:model/Item.hbm.xml not found see exception.log for exception details。”尽管It​​em.hbm.xml在那里。

回答