hibernate正向工程生成一对多关系模型无报错,但是只生成了一张表
澳门第一娛乐城官网
澳门第一娛乐城官网
当前位置 : 澳门第一娛乐城官网 > 澳门银河官网

hibernate正向工程生成一对多关系模型无报错,但是只生成了一张表

我现在准备做正向工程,User客户和Order订单的一对多关系

下面是他们的实体类

package com.cw.entity;

import java.util.Set;

public class User implements java.io.Serializable {
    private Integer id;
    private String username;
    private String password;
    private Set<Order> order;
    public Integer getId {
        return id;
    }
    public void setIdInteger id {
        this.id = id;
    }
    public String getUsername {
        return username;
    }
    public void setUsernameString username {
        this.username = username;
    }
    public String getPassword {
        return password;
    }
    public void setPasswordString password {
        this.password = password;
    }
    public Set<Order> getOrder {
        return order;
    }
    public void setOrderSet<Order> order {
        this.order = order;
    }
    public UserString username, String password, Set<Order> order {
        super;
        this.username = username;
        this.password = password;
        this.order = order;
    }
    
    
}

package com.cw.entity;

public class Order implements java.io.Serializable {
    private Integer id;
    private User user;
    private String shop;
    public Integer getId {
        return id;
    }
    public void setIdInteger id {
        this.id = id;
    }
    public User getUser {
        return user;
    }
    public void setUserUser user {
        this.user = user;
    }
    public String getShop {
        return shop;
    }
    public void setShopString shop {
        this.shop = shop;
    }
    public OrderUser user, String shop {
        super;
        this.user = user;
        this.shop = shop;
    }
    
}

下面是hbm.xml配置文件

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- 
    Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
    <class name="com.cw.entity.User" table="user" catalog="test">
        <id name="id" type="java.lang.Integer">
            <column name="id" />
            <generator class="native" />
        </id>
        <property name="username" type="java.lang.String">
            <column name="username" />
        </property>
        <property name="password" type="java.lang.String">
            <column name="password" />
        </property>
        <set name="order" cascade="save-update" inverse="true">
            <key column="order"></key>
            <one-to-many class="com.cw.entity.Order"/>
        </set>
    </class>
</hibernate-mapping>

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- 
    Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
    <class name="com.cw.entity.Order" table="order" catalog="test">
        <id name="id" type="java.lang.Integer">
            <column name="id" />
            <generator class="native" />
        </id>
        <!-- <property name="user" type="com.cw.entity.User">
            <column name="user" />
        </property> -->
        <property name="shop" type="java.lang.String">
            <column name="shop" />
        </property>
        <many-to-one name="user" class="com.cw.entity.User" cascade="all" column="user"></many-to-one>
    </class>
</hibernate-mapping>

其他配置我都检查了没问题,hibernate.cfg.xml也没问题(已经加了两个实体模型的配置项以及hbm2ddl配置),但是执行

package com.cw.entity;

import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.classic.Session;
import org.hibernate.id.Configurable;

public class Test {

    /**
     * @param args
     */
    public static void mainString[] args {
        // TODO Auto-generated method stub
        Configuration configure = new Configuration.configure;
        SessionFactory buildSessionFactory = configure.buildSessionFactory;
        Session session = buildSessionFactory.openSession;
        Transaction tx = session.beginTransaction;
        tx.commit;
    }

}

之后只有user表生成了,order表没有生成,请问一下现在问题是出在哪?

用注解吧,现在流行注解

栏目列表

广告位

澳门第一娛乐城官网