hibernate如何为oracale数据库自动建表?

解决方案 »

  1.   

    两种方法:
    一种是hibernate.cfg.xml设置下:<property name="hbm2ddl.auto">create</property>
    一种是用代码写法:public class ExportDB { public static void main(String[] args) {

    //读取hibernate.cfg.xml文件
    Configuration cfg = new Configuration().configure();

    SchemaExport export = new SchemaExport(cfg);

    export.create(true, true);
    }
    }
      

  2.   

    运行的时候只运行tomcat就能自动生成?还是要运行别的文件?
      

  3.   

    是啊,我是个初学者,还没学过hibernate,但是我要调试个别人给我的代码,这代码是通过hibernate自动建表的,我只运行了tomcat但是oracle中没有建表啊,我想是不是还应该运行下别的哪个东西才行呢?代码应该是没有错误的!!!高手来帮我啊!!!!
      

  4.   

    Hibernate 自动建表对于初学者来说不推荐,企业中用的最多的是
        SchemaExport export = new SchemaExport(cfg);
            
            export.create(true, true);
    除非你到了一定的级别才让你做配制文件这块!
      

  5.   

    SchemaExport export = new SchemaExport(
    new Configuration().configure()); 
    export.create(true, true); 
      

  6.   

    2009-4-25 21:35:07 org.apache.catalina.core.AprLifecycleListener lifecycleEvent
    信息: The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: D:\Myeclipse\bin;D:\apache-tomcat-5.5.20\bin
    2009-4-25 21:35:07 org.apache.coyote.http11.Http11BaseProtocol init
    信息: Initializing Coyote HTTP/1.1 on http-8080
    2009-4-25 21:35:07 org.apache.catalina.startup.Catalina load
    信息: Initialization processed in 1936 ms
    2009-4-25 21:35:07 org.apache.catalina.core.StandardService start
    信息: Starting service Catalina
    2009-4-25 21:35:07 org.apache.catalina.core.StandardEngine start
    信息: Starting Servlet Engine: Apache Tomcat/5.5.20
    2009-4-25 21:35:08 org.apache.catalina.core.StandardHost start
    信息: XML validation disabled
    log4j:WARN No appenders could be found for logger (org.apache.commons.digester.Digester.sax).
    log4j:WARN Please initialize the log4j system properly.
    2009-4-25 21:35:10 org.apache.catalina.core.StandardContext start
    严重: Error filterStart
    2009-4-25 21:35:10 org.apache.catalina.core.StandardContext start
    严重: Context [/Air] startup failed due to previous errors
    2009-4-25 21:35:10 org.apache.catalina.core.ApplicationContext log
    信息: org.apache.webapp.balancer.BalancerFilter: init(): ruleChain: [org.apache.webapp.balancer.RuleChain: [org.apache.webapp.balancer.rules.URLStringMatchRule: Target string: News / Redirect URL: http://www.cnn.com], [org.apache.webapp.balancer.rules.RequestParameterRule: Target param name: paramName / Target param value: paramValue / Redirect URL: http://www.yahoo.com], [org.apache.webapp.balancer.rules.AcceptEverythingRule: Redirect URL: http://jakarta.apache.org]]
    2009-4-25 21:35:10 org.apache.catalina.core.ApplicationContext log
    信息: ContextListener: contextInitialized()
    2009-4-25 21:35:10 org.apache.catalina.core.ApplicationContext log
    信息: SessionListener: contextInitialized()
    2009-4-25 21:35:11 org.apache.catalina.core.ApplicationContext log
    信息: ContextListener: contextInitialized()
    2009-4-25 21:35:11 org.apache.catalina.core.ApplicationContext log
    信息: SessionListener: contextInitialized()
    log4j:WARN No appenders could be found for logger (org.apache.commons.digester.Digester.sax).
    log4j:WARN Please initialize the log4j system properly.
    log4j:WARN No appenders could be found for logger (org.apache.commons.digester.Digester.sax).
    log4j:WARN Please initialize the log4j system properly.
    2009-4-25 21:35:20 org.apache.coyote.http11.Http11BaseProtocol start
    信息: Starting Coyote HTTP/1.1 on http-8080
    2009-4-25 21:35:21 org.apache.jk.common.ChannelSocket init
    信息: JK: ajp13 listening on /0.0.0.0:8009
    2009-4-25 21:35:21 org.apache.jk.server.JkMain start
    信息: Jk running ID=0 time=0/94  config=null
    2009-4-25 21:35:21 org.apache.catalina.storeconfig.StoreLoader load
    信息: Find registry server-registry.xml at classpath resource
    2009-4-25 21:35:21 org.apache.catalina.startup.Catalina start
    信息: Server startup in 14045 ms
    就是这个错误!谁知道是怎么回事啊?
      

  7.   

    帮你顶一下吧 我也遇到同样的问题  mysql数据库 只不过控制台显示了2条sql语句 create ...  但是数据库里只生成了一个表 ... 郁闷啊