通过程序,自己手动写建表语句挺麻烦的。
如下所示:
<property name="hbm2ddl.auto">update</property>
将update改为create,然后运行JUNIT的单个方法,比如save()即可。
然后进入mysql查看建表语句:
mysql> use hibernate;
Database changed
mysql> show create table teacher;
+---------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+---------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| teacher | CREATE TABLE `teacher` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`birthDate` datetime DEFAULT NULL,
`gender` varchar(255) DEFAULT NULL,
`good` bit(1) NOT NULL,
`name` varchar(255) DEFAULT NULL,
`title` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=gbk |
+---------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set
mysql>
大致就这样,很简单,呵呵呵。