我的休眠会话有问题。我试图测试它引发一个选择查询,但我不明白为什么它不起作用。当我在下面的代码中调用buildSessionFactory方法时,服务器似乎无穷大。
package fr.utils;
import org.hibernate.HibernateException;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
public class HibernateConfig {
public static SessionFactory getConfiguredSessionFactory() throws HibernateException {
try {
Configuration config = new Configuration();
config.configure();
StandardServiceRegistryBuilder serviceRegistry = new StandardServiceRegistryBuilder().applySettings(config.getProperties());
SessionFactory sessionFactory = config.buildSessionFactory(serviceRegistry.build());
return sessionFactory;
}
catch (HibernateException e) {
e.printStackTrace();
return null;
}
}
}
我的休眠配置文件位于src / main / ressources文件夹中,并且在其中包含此代码
<?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>
<!-- SQL Dialect -->
<property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
<!-- Database Connection Settings -->
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:8888/yugioh_j2ee</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password"></property>
<property name="hibernate.connection.pool_size">10</property>
<property name="show_sql">true</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="spring.jpa.hibernate.ddl-auto">create</property>
<property name="hibernate.cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>
<!-- Specifying Session Context -->
<property name="hibernate.current_session_context_class">org.hibernate.context.internal.ThreadLocalSessionContext</property>
<!-- Mapping With Model Class Containing Annotations -->
<mapping class="fr.metier.Player"/>
</session-factory>
</hibernate-configuration>
我真的不明白为什么它不起作用。
感谢您的帮助。