SSH项目,没有数据库,想通过hibernate的hbm.xml 文件得到数据库表结构(SQLSERVER2005的SQL代码)··· 50
四个hbm.xml文件:Board.hbm.xml<?xmlversion="1.0"encoding="utf-8"?><!DOCTYPEhibernate-mappi...
四个hbm.xml文件:
Board.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.bbs.entity.Board" table="BOARD" schema="SYSTEM">
<id name="boardid" type="java.lang.Integer">
<column name="BOARDID" precision="38" scale="0" />
<generator class="increment"></generator>
</id>
<property name="boardname" type="java.lang.String">
<column name="BOARDNAME" length="100" not-null="true" />
</property>
<property name="parentid" type="java.lang.Integer">
<column name="PARENTID" precision="38" scale="0" not-null="true" />
</property>
<set name="topics" inverse="true">
<key>
<column name="BOARDID" precision="38" scale="0" not-null="true" />
</key>
<one-to-many class="com.bbs.entity.Topic" />
</set>
</class>
</hibernate-mapping>
Reply.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.bbs.entity.Reply" table="REPLY" schema="SYSTEM">
<id name="replyid" type="java.lang.Integer">
<column name="REPLYID" precision="38" scale="0" />
<generator class="increment" />
</id>
<many-to-one name="topic" class="com.bbs.entity.Topic" fetch="select">
<column name="TOPICID" precision="38" scale="0" not-null="true" />
</many-to-one>
<many-to-one name="userInfo" class="com.bbs.entity.UserInfo" fetch="select">
<column name="USERID" precision="38" scale="0" not-null="true" />
</many-to-one>
<property name="title" type="java.lang.String">
<column name="TITLE" length="100" not-null="true" />
</property>
<property name="content" type="java.lang.String">
<column name="CONTENT" length="2000" not-null="true" />
</property>
<property name="publishtime" type="java.util.Date">
<column name="PUBLISHTIME" length="7" not-null="true" />
</property>
<property name="modifytime" type="java.util.Date">
<column name="MODIFYTIME" length="7" not-null="true" />
</property>
</class>
</hibernate-mapping> 展开
Board.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.bbs.entity.Board" table="BOARD" schema="SYSTEM">
<id name="boardid" type="java.lang.Integer">
<column name="BOARDID" precision="38" scale="0" />
<generator class="increment"></generator>
</id>
<property name="boardname" type="java.lang.String">
<column name="BOARDNAME" length="100" not-null="true" />
</property>
<property name="parentid" type="java.lang.Integer">
<column name="PARENTID" precision="38" scale="0" not-null="true" />
</property>
<set name="topics" inverse="true">
<key>
<column name="BOARDID" precision="38" scale="0" not-null="true" />
</key>
<one-to-many class="com.bbs.entity.Topic" />
</set>
</class>
</hibernate-mapping>
Reply.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.bbs.entity.Reply" table="REPLY" schema="SYSTEM">
<id name="replyid" type="java.lang.Integer">
<column name="REPLYID" precision="38" scale="0" />
<generator class="increment" />
</id>
<many-to-one name="topic" class="com.bbs.entity.Topic" fetch="select">
<column name="TOPICID" precision="38" scale="0" not-null="true" />
</many-to-one>
<many-to-one name="userInfo" class="com.bbs.entity.UserInfo" fetch="select">
<column name="USERID" precision="38" scale="0" not-null="true" />
</many-to-one>
<property name="title" type="java.lang.String">
<column name="TITLE" length="100" not-null="true" />
</property>
<property name="content" type="java.lang.String">
<column name="CONTENT" length="2000" not-null="true" />
</property>
<property name="publishtime" type="java.util.Date">
<column name="PUBLISHTIME" length="7" not-null="true" />
</property>
<property name="modifytime" type="java.util.Date">
<column name="MODIFYTIME" length="7" not-null="true" />
</property>
</class>
</hibernate-mapping> 展开
4个回答
展开全部
给你一个我写的工具,里面的方法,都有注释,设置show_sql为true,运行这里面的建表方法,就能看到你要的表结构,只要是配置文件写对了,可以数据出任何hibernate支持的数据库的建表sql
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;
public class HibernateUtils {
private static Configuration conf;
private static SessionFactory factory;
private static SchemaExport se;
static {
conf = new Configuration();
conf.configure(HibernateUtils.class.getClassLoader().getResource("hibernate.cfg.xml"));
factory = conf.buildSessionFactory();
se = new SchemaExport(conf);
}
public static Session getSession() {
return factory.openSession();
}
public static SessionFactory getSessionFactory() {
return factory;
}
/**
* 建表
* create(boolean script, boolean export)
* script 是否打印DDL语句
* export 是否导入脚本到数据库
*/
public static void creatTable() {
se.create(true, true);
}
/**
* 删除所有的表
*/
public static void dropTable() {
se.drop(true, true);
}
/**
* 先删除所有的表再创建所有的表
* 达到清空所有table的目的
*/
public static void clearTable() {
dropTable();
creatTable();
}
}
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;
public class HibernateUtils {
private static Configuration conf;
private static SessionFactory factory;
private static SchemaExport se;
static {
conf = new Configuration();
conf.configure(HibernateUtils.class.getClassLoader().getResource("hibernate.cfg.xml"));
factory = conf.buildSessionFactory();
se = new SchemaExport(conf);
}
public static Session getSession() {
return factory.openSession();
}
public static SessionFactory getSessionFactory() {
return factory;
}
/**
* 建表
* create(boolean script, boolean export)
* script 是否打印DDL语句
* export 是否导入脚本到数据库
*/
public static void creatTable() {
se.create(true, true);
}
/**
* 删除所有的表
*/
public static void dropTable() {
se.drop(true, true);
}
/**
* 先删除所有的表再创建所有的表
* 达到清空所有table的目的
*/
public static void clearTable() {
dropTable();
creatTable();
}
}
展开全部
根据上面的代码来看,数据库名为SYSTEM,数据表至少有四个。分别是BOARD ,REPLY,TOPIC,另一个暂且命名为USER吧。其中BOARD表的各字段如下:boardid( 主键 int 自动增长), boardname (varchar(100) 非空), parentid (int 非空)。REPLY 表的各字段如下:replyid ( 主键 int 自动增长), topicid (外键,int 非空),userid (外键,int 非空),title ( varchar(100) 非空) ,content (text 非空),publishtime( Date 非空),modifytime(Date 非空)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Topic.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.bbs.entity.Topic" table="TOPIC" schema="SYSTEM">
<id name="topicid" type="java.lang.Integer">
<column name="TOPICID" precision="38" scale="0" />
<generator class="increment" />
</id>
<many-to-one name="board" class="com.bbs.entity.Board" fetch="select">
<column name="BOARDID" precision="38" scale="0" not-null="true" />
</many-to-one>
<many-to-one name="userInfo" class="com.bbs.entity.UserInfo" fetch="select">
<column name="USERID" precision="38" scale="0" not-null="true" />
</many-to-one>
<property name="title" type="java.lang.String">
<column name="TITLE" length="100" not-null="true" />
</property>
<property name="content" type="java.lang.String">
<column name="CONTENT" length="2000" not-null="true" />
</property>
<property name="publishtime" type="java.util.Date">
<column name="PUBLISHTIME" length="7" not-null="true" />
</property>
<property name="modifytime" type="java.util.Date">
<column name="MODIFYTIME" length="7" not-null="true" />
</property>
<set name="replies" inverse="true">
<key>
<column name="TOPICID" precision="38" scale="0" not-null="true" />
</key>
<one-to-many class="com.bbs.entity.Reply" />
</set>
</class>
</hibernate-mapping>
UserInfo.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.bbs.entity.UserInfo" table="USERINFO" schema="SYSTEM">
<id name="userid" type="java.lang.Integer">
<column name="USERID" precision="38" scale="0" />
<generator class="increment"></generator>
</id>
<property name="username" type="java.lang.String">
<column name="USERNAME" length="100" not-null="true" />
</property>
<property name="userpass" type="java.lang.String">
<column name="USERPASS" length="20" not-null="true" />
</property>
<property name="head" type="java.lang.String">
<column name="HEAD" length="100" not-null="true" />
</property>
<property name="regtime" type="java.util.Date">
<column name="REGTIME" length="7" not-null="true" />
</property>
<property name="gender" type="java.lang.Integer">
<column name="GENDER" precision="38" scale="0" not-null="true" />
</property>
<set name="topics" inverse="true">
<key>
<column name="USERID" precision="38" scale="0" not-null="true" />
</key>
<one-to-many class="com.bbs.entity.Topic" />
</set>
<set name="replies" inverse="true">
<key>
<column name="USERID" precision="38" scale="0" not-null="true" />
</key>
<one-to-many class="com.bbs.entity.Reply" />
</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.bbs.entity.Topic" table="TOPIC" schema="SYSTEM">
<id name="topicid" type="java.lang.Integer">
<column name="TOPICID" precision="38" scale="0" />
<generator class="increment" />
</id>
<many-to-one name="board" class="com.bbs.entity.Board" fetch="select">
<column name="BOARDID" precision="38" scale="0" not-null="true" />
</many-to-one>
<many-to-one name="userInfo" class="com.bbs.entity.UserInfo" fetch="select">
<column name="USERID" precision="38" scale="0" not-null="true" />
</many-to-one>
<property name="title" type="java.lang.String">
<column name="TITLE" length="100" not-null="true" />
</property>
<property name="content" type="java.lang.String">
<column name="CONTENT" length="2000" not-null="true" />
</property>
<property name="publishtime" type="java.util.Date">
<column name="PUBLISHTIME" length="7" not-null="true" />
</property>
<property name="modifytime" type="java.util.Date">
<column name="MODIFYTIME" length="7" not-null="true" />
</property>
<set name="replies" inverse="true">
<key>
<column name="TOPICID" precision="38" scale="0" not-null="true" />
</key>
<one-to-many class="com.bbs.entity.Reply" />
</set>
</class>
</hibernate-mapping>
UserInfo.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.bbs.entity.UserInfo" table="USERINFO" schema="SYSTEM">
<id name="userid" type="java.lang.Integer">
<column name="USERID" precision="38" scale="0" />
<generator class="increment"></generator>
</id>
<property name="username" type="java.lang.String">
<column name="USERNAME" length="100" not-null="true" />
</property>
<property name="userpass" type="java.lang.String">
<column name="USERPASS" length="20" not-null="true" />
</property>
<property name="head" type="java.lang.String">
<column name="HEAD" length="100" not-null="true" />
</property>
<property name="regtime" type="java.util.Date">
<column name="REGTIME" length="7" not-null="true" />
</property>
<property name="gender" type="java.lang.Integer">
<column name="GENDER" precision="38" scale="0" not-null="true" />
</property>
<set name="topics" inverse="true">
<key>
<column name="USERID" precision="38" scale="0" not-null="true" />
</key>
<one-to-many class="com.bbs.entity.Topic" />
</set>
<set name="replies" inverse="true">
<key>
<column name="USERID" precision="38" scale="0" not-null="true" />
</key>
<one-to-many class="com.bbs.entity.Reply" />
</set>
</class>
</hibernate-mapping>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询