@@ -0,0 +1,1809 @@
+package org.fastnate.data;%0A%0Aimport java.io.IOException;%0Aimport java.sql.Connection;%0Aimport java.sql.SQLException;%0Aimport java.util.Properties;%0A%0Aimport org.hibernate.SessionFactory;%0Aimport org.hibernate.SessionFactoryObserver;%0Aimport org.hibernate.boot.SchemaAutoTooling;%0Aimport org.hibernate.boot.spi.SessionFactoryOptions;%0Aimport org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;%0Aimport org.hibernate.engine.spi.SessionFactoryImplementor;%0Aimport org.hibernate.tool.hbm2ddl.ImportScriptException;%0A%0A/**%0A * Imports data on startup of Hibernate, if %7B@link SessionFactoryOptions#getSchemaAutoTooling() schema auto tooling%7D is%0A * set either to %7B@link SchemaAutoTooling#CREATE%7D or %7B@link SchemaAutoTooling#CREATE_DROP%7D.%0A *%0A * @author Tobias Liefke%0A */%0Apublic class DatabaseStartupImport implements SessionFactoryObserver %7B%0A%0A%09private static final long serialVersionUID = 1L;%0A%0A%09@Override%0A%09public void sessionFactoryClosed(final SessionFactory factory) %7B%0A%09%09// Nothing to do%0A%09%7D%0A%0A%09@Override%0A%09public void sessionFactoryCreated(final SessionFactory factory) %7B%0A%09%09// Only import, if Hibernate has just created an empty database%0A%09%09final SchemaAutoTooling autoTooling = factory.getSessionFactoryOptions().getSchemaAutoTooling();%0A%09%09if (autoTooling == SchemaAutoTooling.CREATE %7C%7C autoTooling == SchemaAutoTooling.CREATE_DROP) %7B%0A%09%09%09// Find a connection%0A%09%09%09final SessionFactoryImplementor sessionFactoryImplementor = (SessionFactoryImplementor) factory;%0A%09%09%09try (Connection connection = sessionFactoryImplementor.getServiceRegistry()%0A%09%09%09%09%09.getService(ConnectionProvider.class).getConnection()) %7B%0A%09%09%09%09// Import data%0A%09%09%09%09new EntityImporter(new Properties()).importData(connection);%0A%09%09%09%7D catch (final SQLException %7C IOException e) %7B%0A%09%09%09%09throw new ImportScriptException(%22Could not import SQL data: %22 + e, e);%0A%09%09%09%7D%0A%09%09%7D%0A%09%7D%0A%7D%0A

Add an example for a connected startup importer