diff --git a/doc/guide/en-US/GuideArtificerServerConfiguration.asciidoc b/doc/guide/en-US/GuideArtificerServerConfiguration.asciidoc
index 06161a933..86a931207 100644
--- a/doc/guide/en-US/GuideArtificerServerConfiguration.asciidoc
+++ b/doc/guide/en-US/GuideArtificerServerConfiguration.asciidoc
@@ -41,11 +41,10 @@ hibernate.connection.password = sa
...
----
-Note that a datasource is *not* required (although recommended). Plain JDBC connections, including external instances,
-are also supported (use `hibernate.connection.url`). However,
-we strongly recommend using an adequate connection pool (HikariCP, C3P0, Proxool, etc.). Without this, since Artificer does not
-configure one out of the box, you'd effectively be using the Hibernate-provided connection pool (not recommended for
-production environments).
+Note that a datasource is *not* required, although we typically recommend them. Plain JDBC connection URLs, including
+external instances, are also fully supported (use `hibernate.connection.url`, `hibernate.connection.username`,
+and `hibernate.connection.password`). If a connection URL is used, Artificer will automatically wrap it with
+HikariCP, a lightweight and extremely performant connection pool library.
Also note that Artificer ships with JDBC drivers for H2, MySQL, and Postgres. With proper values in artificer.properties,
these databases should simply work out-of-the-box. However, due to licensing, we cannot include the drivers for
diff --git a/installer/src/main/resources/updates/artificer.properties b/installer/src/main/resources/updates/artificer.properties
index 24e23e59a..90bcb539c 100644
--- a/installer/src/main/resources/updates/artificer.properties
+++ b/installer/src/main/resources/updates/artificer.properties
@@ -24,8 +24,6 @@ hibernate.show_sql = false
hibernate.dialect = org.hibernate.dialect.H2Dialect
hibernate.connection.driver_class = org.h2.Driver
hibernate.connection.datasource = java:jboss/datasources/artificerH2
-hibernate.connection.username = sa
-hibernate.connection.password = sa
hibernate.cache.use_second_level_cache = false
#hibernate.cache.region.factory_class =
#hibernate.cache.default_cache_concurrency_strategy = transactional
diff --git a/pom.xml b/pom.xml
index 15970d55c..fb6474edb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -621,7 +621,11 @@
lucene-analyzers
${version.org.apache.lucene}
-
+
+ com.zaxxer
+ HikariCP-java6
+ 2.3.8
+
jstl
diff --git a/repository/hibernate/pom.xml b/repository/hibernate/pom.xml
index a48e3df6b..c57e5b6af 100644
--- a/repository/hibernate/pom.xml
+++ b/repository/hibernate/pom.xml
@@ -73,6 +73,10 @@
javassist
runtime
+
+ com.zaxxer
+ HikariCP-java6
+
diff --git a/repository/hibernate/src/main/java/org/artificer/repository/hibernate/HibernateUtil.java b/repository/hibernate/src/main/java/org/artificer/repository/hibernate/HibernateUtil.java
index af8ec0d78..63f6ae2c9 100644
--- a/repository/hibernate/src/main/java/org/artificer/repository/hibernate/HibernateUtil.java
+++ b/repository/hibernate/src/main/java/org/artificer/repository/hibernate/HibernateUtil.java
@@ -15,6 +15,8 @@
*/
package org.artificer.repository.hibernate;
+import com.zaxxer.hikari.HikariConfig;
+import com.zaxxer.hikari.HikariDataSource;
import org.artificer.common.ArtificerConfig;
import org.artificer.common.ArtificerException;
import org.artificer.common.error.ArtificerNotFoundException;
@@ -29,7 +31,9 @@
import javax.persistence.EntityManagerFactory;
import javax.persistence.NoResultException;
import javax.persistence.Query;
+import java.io.PrintWriter;
import java.util.Map;
+import java.util.Properties;
/**
* @author Brett Meyer.
@@ -88,6 +92,36 @@ private static EntityManager entityManager() {
if (entityManagerFactory == null) {
// Pass in all hibernate.* settings from artificer.properties
Map properties = ArtificerConfig.getConfigProperties("hibernate");
+
+ // If a connection is used, we *cannot* rely on Hibernate's built-in connection pool. Instead,
+ // automatically set up HikariCP.
+ if (properties.containsKey("hibernate.connection.url")) {
+ String connectionUrl = (String) properties.remove("hibernate.connection.url");
+ String username = (String) properties.remove("hibernate.connection.username");
+ String password = (String) properties.remove("hibernate.connection.password");
+
+ HikariConfig hikariConfig = new HikariConfig();
+ hikariConfig.setJdbcUrl(connectionUrl);
+ hikariConfig.setUsername(username);
+ hikariConfig.setPassword(password);
+
+ // In case we're using MySQL, these settings are recommended by HikariCP:
+ hikariConfig.addDataSourceProperty("cachePrepStmts", "true");
+ hikariConfig.addDataSourceProperty("prepStmtCacheSize", "250");
+ hikariConfig.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
+ hikariConfig.addDataSourceProperty("useServerPrepStmts", "true");
+
+ String dialect = (String) properties.get("hibernate.dialect");
+ if (dialect != null && dialect.contains("PostgreSQL")) {
+ // The JDBC jar verion in the IP BOM does not support Connection.isValid(), so need to use this:
+ hikariConfig.setConnectionTestQuery("SELECT 1");
+ }
+
+ HikariDataSource hikariDataSource = new HikariDataSource(hikariConfig);
+
+ properties.put("hibernate.connection.datasource", hikariDataSource);
+ }
+
entityManagerFactory = new HibernatePersistence().createEntityManagerFactory(persistenceUnit, properties);
}
return entityManagerFactory.createEntityManager();
diff --git a/repository/test/src/test/resources/META-INF/persistence.xml b/repository/test/src/test/resources/META-INF/persistence.xml
index 85f8305f9..e67e7e331 100644
--- a/repository/test/src/test/resources/META-INF/persistence.xml
+++ b/repository/test/src/test/resources/META-INF/persistence.xml
@@ -24,9 +24,16 @@
-
-
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/test/src/test/resources/artificer.properties b/test/src/test/resources/artificer.properties
index 56e21c221..f21aec53d 100644
--- a/test/src/test/resources/artificer.properties
+++ b/test/src/test/resources/artificer.properties
@@ -10,8 +10,6 @@ hibernate.show_sql = false
hibernate.dialect = org.hibernate.dialect.H2Dialect
hibernate.connection.driver_class = org.h2.Driver
hibernate.connection.datasource = java:jboss/datasources/artificerH2
-hibernate.connection.username = sa
-hibernate.connection.password = sa
hibernate.cache.use_second_level_cache = false
#hibernate.cache.region.factory_class =
#hibernate.cache.default_cache_concurrency_strategy = transactional