public static void main(String[] args) { Configuration hello =new Configuration(); Properties properties = new Properties(); properties.setProperty(Environment.DIALECT, MySQL5Dialect.class.getName()); hello.setProperties(properties); hello.addAnnotatedClass(Hello.class); hello.addAnnotatedClass(Hello1.class); SchemaExport schemaExport = new SchemaExport(hello); schemaExport.setDelimiter(";"); // schemaExport.setOutputFile(String.format("%s_%s.%s ", new Object[] {"ddl", dialect.name().toLowerCase(), "sql" })); boolean consolePrint = true; boolean exportInDatabase = false; // schemaExport.create(consolePrint, exportInDatabase); schemaExport.create(Target.SCRIPT); }
@Test public void testDbSchema() { MetadataSources metadata = new MetadataSources(new StandardServiceRegistryBuilder() .applySetting("hibernate.dialect", "org.hibernate.dialect.H2Dialect").build()); metadata.addAnnotatedClass(ConsoleEntity.class); metadata.addAnnotatedClass(GameEntity.class); metadata.addAnnotatedClass(UserEntity.class); metadata.addAnnotatedClass(RoleEntity.class); metadata.addAnnotatedClass(LibraryEntity.class); metadata.addAnnotatedClass(BorrowEntity.class); SchemaExport export = new SchemaExport((MetadataImplementor) metadata.buildMetadata()); export.create(Target.SCRIPT); }
public static void main(String[] args) { try { DriverService driverService = CONNECTION_CONFIG.loadDriver(); HibernateDaoContext context = new HibernateDaoContext(driverService, ApplicationConfig.CONFIG); // Stream.of(context.schemaCreationScript()).forEach(System.out::println); new SchemaUpdate(context.configuration).execute(Target.SCRIPT); } catch (Exception ex) { ex.printStackTrace(); } }
@RequestMapping("/admin/schema") public void exportSchema(final Model model) throws IOException { final SchemaExport export = new SchemaExport(localSessionFactoryBuilder); final File f = Files.createTempFile(null, null).toFile(); export.setOutputFile(f.getCanonicalPath()); export.execute(Target.SCRIPT, Type.CREATE); model.addAttribute("ddl", FileUtils.readFileToString(f)); model.addAttribute("file", f.getCanonicalPath()); }
@Test public void exportSchemaShouldCreateSqlFile() { final SchemaExport export = new SchemaExport(localSessionFactoryBuilder); export.setOutputFile(OUTPUT_FILE_NAME); export.execute(Target.SCRIPT, Type.CREATE); final File f = new File(OUTPUT_FILE_NAME); assertTrue(f.exists()); }