try {
System.out.println("setupConfig: Current dir = " + (new File(".")).getCanonicalPath());
// prepare the configuration
Configuration configuration = new Configuration().setProperty(AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS,
"true");
configuration.getProperties().put(AvailableSettings.JTA_PLATFORM, JBossAppServerJtaPlatform.class);
configuration.setProperty(Environment.HBM2DDL_AUTO, "create-drop");
configuration.setProperty(Environment.DATASOURCE, "java:jboss/datasources/ExampleDS");
// fetch the properties
Properties properties = new Properties();
properties.putAll(configuration.getProperties());
Environment.verifyProperties(properties);
ConfigurationHelper.resolvePlaceHolders(properties);
// build the serviceregistry
final BootstrapServiceRegistryBuilder bootstrapbuilder = new BootstrapServiceRegistryBuilder();
builder = new ServiceRegistryBuilder(bootstrapbuilder.build()).applySettings(properties);
serviceRegistry = builder.buildServiceRegistry();
// Create the SessionFactory from Configuration
sessionFactory = configuration.configure("hibernate.cfg.xml").buildSessionFactory(serviceRegistry);
// Session session = sessionFactory.openSession();
} catch (Throwable ex) { // Make sure you log the exception, as it might be swallowed
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);