我尝试使用 HikariCP 池连接,但我无法启动应用程序,因为我一直得到一个来自创建会话的空对象。
这是我的配置:
系统
- 休眠 4.3.6.Final
- MariaDB v10.0 (x64)
HibernateUtil 类
public class HibernateUtil {
private static SessionFactory sessionFactory;
private static SessionFactory buildSessionFactory() {
try {
Configuration configuration = new Configuration();
configuration.configure("hibernate.cfg.xml");
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
return sessionFactory;
}
catch (HibernateException ex) {
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
if (sessionFactory == null) {
sessionFactory = buildSessionFactory();
}
return sessionFactory;
}
}
休眠.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Datos de conexión a la BD -->
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3307/******?zeroDateTimeBehavior=convertToNull</property>
<property name="hibernate.connection.username">****</property>
<property name="hibernate.connection.password">****</property>
<property name="javax.persistence.validation.mode">none</property>
<!-- Configuración de sesión -->
<property name="connection.release_mode">after_transaction</property>
<property name="current_session_context_class">thread</property>
<!-- Configuración de la salida SQL y estadísticas -->
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="hibernate.temp.use_jdbc_metadata_defaults">false</property>
<!-- Pool de conexiones -->
<property name="hibernate.connection.provider_class">org.mariadb.jdbc.MySQLDataSource</property>
<!-- Enable Hibernate's current session context -->
<property name="hibernate.cache.use_second_level_cache">false</property>
<property name="hibernate.cache.use_query_cache">false</property>
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
</session-factory>
</hibernate-configuration>
日志
准备使用过滤器构建会话工厂:{} HHH000130:实例化显式连接提供程序:应用程序启动方法中的 org.mariadb.jdbc.MySQLDataSource 异常