只要在hibernate.cfg.xml添加这句话,
<property name="hibernate.hbm2ddl.auto">
update:表示自动根据model对象来更新表结构,启动h
还有其他的参数:
create:启动hibernate时,自动删除原来的表,
create-drop:启动hibernate时,
validate: 加载hibernate时,验证创建数据库表结构
如果发现数据库表丢失或新增,请检查hibernate.
PS:数据库要预先建立好,因为hibernate只会建表,