hibernate.hbm2ddl.auto 属性设置为true,但是不能生成数据库表

来源:百度知道 编辑:UC知道 时间:2024/06/07 12:29:50
hibernate.cfg.xml配置如下
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:zy</property>
<property name="hibernate.connection.username">tom</property>
<property name="hibernate.connection.password">aaaaaa</property>
<property name="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<mapping resource="net/huadong/exammis/pojo/Person.hbm.xml"/>
</session-factory>
</hibernate-configuration>
看网上说这样配置hibernate.hbm2ddl.au

update只是更新表结构,但不能生成
请仔细参考一下hibernate.hbm2ddl.auto的配置参数,有以下四种:
validate:加载hibernate时,验证创建数据库表结构
create:每次加载hibernate,重新创建数据库表结构,这就是导致数据库表数据丢失的原因。
create-drop:加载hibernate时创建,退出是删除表结构
update:加载hibernate自动更新数据库结构

所以,你可以先用create属性,然后运行一次后改用update,以免数据丢收

将值设置为 update 就可以自动生成数据表了!

通过sql语句去创建吧。用这个配置,不能对单个表进行操作

链接串改为jdbc:oracle:thin:tom/aaaaaa@localhost:1521:zy试试吧,
oracle的链接有点变态。