日期:2014-05-19  浏览次数:20796 次

Hibernate在项目启动时自动建表
[code=java]
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="hibernate.connection.url" >jdbc:mysql://localhost:3306/reg</property>
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.connection.password">root</property>
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.hbm2ddl.auto">create</property>
        <property name="current_session_context_class">thread</property>
        <property name="show_sql">true</property>
        
        <mapping resource="entity/User.hbm.xml"/>
        <mapping resource="entity/Order.hbm.xml"/>
    </session-factory>
</hibernate-configuration>

[/code]
上面是我的Hibernate.hbm.xml代码,在我启动项目的时候不能自动创建表。这是什么原因呢
------解决方案--------------------
Hibernate.hbm.xml?这个配置文件是干嘛的..难道你有Hibernate表?
------解决方案--------------------

public class ExportUtil {
public static void main(String[] args) {
Configuration config = new Configuration();
config.configure("hibernate.cfg.xml");
SchemaExport export = new SchemaExport(config);
export.create(true, true);
}
}

是不是要这个~~~~
------解决方案--------------------
数据库是要自己建的不知道你建了没,这个应该会建表的。
------解决方案--------------------
楼主是想说明什么问题啊?
------解决方案--------------------
我只看到了连数据库的一些参数,没看出哪里是建表。不知道
<mapping resource="entity/User.hbm.xml"/>         
<mapping resource="entity/Order.hbm.xml"/>
这两个映射文件有没有问题,还有是不是先建好了数据库。 
------解决方案--------------------
   <property name="hibernate.hbm2ddl.auto">create</property>
  这里的参数还可以设置all,你试下呗
------解决方案--------------------
Hibernate.hbm.xml??文件名应该是hibernate.cfg.xml
xxxx.hbm.xml 是实体映射的
------解决方案--------------------
引用:
Hibernate.hbm.xml??文件名应该是hibernate.cfg.xml
xxxx.hbm.xml 是实体映射的

其次LZ你看下你是否已经有了数据库,然后看下你的实体映射文件是否正确,以上这些验证没有问题,那么肯定会创建表的。