java - Could not open Hibernate Session for transaction on First Login -


i have full operating spring mvc application running spring security following error whenever server hasn't been active in while , tries login:

http status 500 - request processing failed; nested exception org.springframework.transaction.cannotcreatetransactionexception: not open hibernate session transaction; nested exception org.hibernate.transactionexception: jdbc begin transaction failed

sometimes after (approximately 5 seconds later) starts work normally.

i searched , found link: http://forum.spring.io/forum/spring-projects/data/13298-could-not-open-hibernate-session-for-transaction-jdbc-begin-failed don't know how "configure connection testing in connection pool configuration".

any advice?

edit:

i found following link set configuration pool:

http://www.codingpedia.org/ama/tomcat-jdbc-connection-pool-configuration-for-production-and-development/

so tried implement in datasource:

<bean id="datasource" class="org.apache.commons.dbcp.basicdatasource"         destroy-method="close">          <property name="driverclassname" value="com.mysql.jdbc.driver" />          <property name="url" value="jdbc:mysql://192.168.254.45:3306/7jogos" />         <property name="password" value="..." />         <property name="username" value="..." />   <!--      configuration pool -->         <property name="validationquery" value="select 1" />         <property name="validationinterval" value="34000" />         <property name="testonborrow" value="true" />         <property name="removeabandoned" value="true" />         <property name="removeabandonedtimeout" value="55" />       </bean> 

but end getting error on validationinterval saying:

multiple annotations found @ line: - no setter found property 'validationinterval' in class 'org.apache.commons.dbcp.basicdatasource'

without stacktrace hard tell sure, dealing expired db connections. hibernate fails start transaction because first statement tries run ("start transaction - via jdbc) fails. again, assume because the underlying db connection got invalidated in meantime.

this can happen due various reason:

  • db settings (most likely)
  • network/firewall
  • local settings, etc.

regardless of source though, have option ensure not happening. if using jdbc pool (like tomcat jdbc pool), can configure pool test , reopen connections if necessary. testonborrow setting example instruct pool test db connection before offering application use. can fine-tune these settings eliminate performance-related concerns.

additional info

you trying implement pooling fine, got variable name: validationinterval wrong.

you getting error because basicdatasource not have variable named that, spring fails set property. take @ javadoc of basicdatasource (link) see configuration variables available you. validationinterval variable can applied on tomcat pooling implementation (what suggested above), 1 choose not have feature.


Comments