I'm building manager web project with Spring MVC , Hibernate and MySQL. When i write the code to list all the regency i have in database. It run very fast in couple first times, but when i reload the page repeatedly (8 - 10 times), my page just keep the loading mode and no sign of stopping. First, i use MSSQL Server then i change to MySQL, nothing changed, i turn off the firewall, still not working.
This my dispatcher-servlet.xml:
<mvc:resources mapping="/resources/**" location="/WEB-INF/resources/" cache- period="31556926"/>
<mvc:annotation-driven />
<context:component-scan base-package="com.hinet.storage" />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver"
p:viewClass=" org.springframework.web.servlet.view.tiles3.TilesView"/>
<bean id="tilesConfigurer"
class="org.springframework.web.servlet.view.tiles3.TilesConfigurer"
p:definitions="/WEB-INF/tiles/tiles.xml"/>
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="/WEB-INF/database.properties" />
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="com.hinet.storage" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.current_session_context_class">thread</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="configurationClass">org.hibernate.cfg.AnnotationConfiguration</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.use_sql_comments">true</prop>
<prop key="hibernate.generate_statistics">true</prop>
</props>
</property>
</bean>
And this is RengencyDAOImpl:
@Repository("regencyDAO")
@Transactional
public class RegencyDAOImpl extends BaseDAOImpl implements RegencyDAO{
@Override
public List<Regency> getRegencies() {
String sql = "from Regency as re where re.isDelete != true";
Query query = this.openSession().createQuery(sql, Regency.class);
List<Regency> regencies = query.list();
return regencies;
}
}
It has given me headache in the past few days! Does anyone know the reason that cause this problem?
I think you exhaust your datasource (ie opening without closing connection). What does openSession()
do? I think it should be something like getCurrentSession()
. If you open new session, you should close it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.