说明:我并不要在服务器启动才自动创建,我要的是在程序里通过某个方法来重建表。如果用hibernate配置文件就可以通过以下的代码来重建表Configuration config = new Configuration().configure(new File("src/hibernate.cfg.xml"));
SchemaExport schemaExport = new SchemaExport(config);
schemaExport.create(true, true);
但是我用了spring,已经在spring配置文件中整合了hibernate的配置文件(hibernate.cfg.xml),所以无法获得"hibernate.cfg.xml"文件,那要怎样才能通过代码的方式来重建数据库表呢?
SchemaExport schemaExport = new SchemaExport(config);
schemaExport.create(true, true);
但是我用了spring,已经在spring配置文件中整合了hibernate的配置文件(hibernate.cfg.xml),所以无法获得"hibernate.cfg.xml"文件,那要怎样才能通过代码的方式来重建数据库表呢?
应该是你运行代码的时候 没数据库的话会通过spring就把数据库创建了……重建的话要不临时把update改成create- -? 应该不太好