title: Could not commit Hibernate transaction; nested exception is org.hibernate.Transaction Exception: JDBC commit failed
body: <p>I am using Windows Azure SQL Server  in my application when i connect to application it shows following error.</p>
  
  <pre><code>org.springframework.transaction.TransactionSystemException: Could not commit Hibernate transaction; nested exception is org.hibernate.Transaction
  Exception: JDBC commit failed
          at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:660)
          at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754)
          at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723)
          at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:393
  )
          at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:120)
          at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
          at org.springframework.aop.interceptor.CustomizableTraceInterceptor.invokeUnderTrace(CustomizableTraceInterceptor.java:256)
          at org.springframework.aop.interceptor.AbstractTraceInterceptor.invoke(AbstractTraceInterceptor.java:110)
          at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
          at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
          at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
          at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:621)
          at com.asman.vote.mypaint.service.UserWorksService$$EnhancerByCGLIB$$803137ef.yesterdayWinner(&lt;generated&gt;)
          at com.asman.vote.mypaint.controller.MainController.yesterdayWinner(MainController.java:102)
          at com.asman.vote.mypaint.controller.MainController$$FastClassByCGLIB$$ff981c3a.invoke(&lt;generated&gt;)
          at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191)
          at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:688)
          at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
          at org.springframework.aop.interceptor.CustomizableTraceInterceptor.invokeUnderTrace(CustomizableTraceInterceptor.java:256)
          at org.springframework.aop.interceptor.AbstractTraceInterceptor.invoke(AbstractTraceInterceptor.java:110)
          at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
          at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
          at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
          at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:621)
          at com.asman.vote.mypaint.controller.MainController$$EnhancerByCGLIB$$c20ad12a.yesterdayWinner(&lt;generated&gt;)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
          at java.lang.reflect.Method.invoke(Unknown Source)
          at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
          at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:
  426)
          at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:414)
          at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
          at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
          at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
          at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
          at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
          at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
          at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
          at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:185)
          at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
          at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:151)
          at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
          at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
          at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
          at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
          at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:269)
          at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
          at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:300)
          at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
          at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
          at java.lang.Thread.run(Unknown Source)
  Caused by: org.hibernate.TransactionException: JDBC commit failed
          at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:161)
          at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:656)
          ... 53 more
  Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: The connection is closed.
          at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:190)
          at com.microsoft.sqlserver.jdbc.SQLServerConnection.checkClosed(SQLServerConnection.java:388)
          at com.microsoft.sqlserver.jdbc.SQLServerConnection.commit(SQLServerConnection.java:1936)
          at org.hibernate.transaction.JDBCTransaction.commitAndResetAutoCommit(JDBCTransaction.java:170)
          at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:146)
          ... 54 more
  </code></pre>
  
  <p>Hibernate.cfg.xml:</p>
  
  <p>..................</p>
  
  <pre><code>&lt;!DOCTYPE hibernate-configuration PUBLIC"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
  "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"&gt;
  &lt;hibernate-configuration&gt;
      &lt;session-factory&gt;
          &lt;property name="hibernate.bytecode.use_reflection_optimizer"&gt;false&lt;/property&gt;
          &lt;property name="hibernate.connection.driver_class"&gt;com.microsoft.sqlserver.jdbc.SQLServerDriver&lt;/property&gt;
          &lt;property name="hibernate.connection.password"&gt;Asman.1234&lt;/property&gt;`
  
          &lt;property name="hibernate.connection.url"&gt;jdbc:sqlserver://mzfoe7t5fn.database.windows.net:1433;databaseName=VOTEMYPAINT;encrypt=false;packetSize=10240;loginTimeout=300&lt;/property&gt;
          &lt;property name="hibernate.connection.username"&gt;SQLAdmin@mzfoe7t5fn&lt;/property&gt;
          &lt;property name="hibernate.dialect"&gt;org.hibernate.dialect.SQLServerDialect&lt;/property&gt;
          &lt;property name="hibernate.search.autoregister_listeners"&gt;false&lt;/property&gt;
          &lt;property name="hibernate.c3p0.min_size"&gt;5&lt;/property&gt;
  
          &lt;mapping class="com.asman.vote.mypaint.to.UserProfile" /&gt;
          &lt;mapping class="com.asman.vote.mypaint.to.Purchasedetails" /&gt;
          &lt;mapping class="com.asman.vote.mypaint.to.Topics" /&gt;
          &lt;mapping class="com.asman.vote.mypaint.to.AgeGroups" /&gt;
          &lt;mapping class="com.asman.vote.mypaint.to.Admin" /&gt;
          &lt;mapping class="com.asman.vote.mypaint.to.TodaysTopic" /&gt;
          &lt;mapping class="com.asman.vote.mypaint.to.UserWorks" /&gt;
          &lt;mapping class="com.asman.vote.mypaint.to.Htmlpages" /&gt;
      &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <h2>Hibernate-context.html:</h2>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans  xmlns="http://www.springframework.org/schema/beans" 
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xmlns:p="http://www.springframework.org/schema/p" 
          xmlns:tx="http://www.springframework.org/schema/tx"
          xmlns:context="http://www.springframework.org/schema/context"
          xsi:schemaLocation="
              http://www.springframework.org/schema/beans 
              http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
              http://www.springframework.org/schema/tx 
              http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
              http://www.springframework.org/schema/context
              http://www.springframework.org/schema/context/spring-context-3.0.xsd"&gt;`
  &lt;context:property-placeholder location="/WEB-INF/spring.properties" /&gt;
  
      &lt;!-- Enable annotation style of managing transactions --&gt;
      &lt;tx:annotation-driven transaction-manager="transactionManager" /&gt;   
  
      &lt;!-- Declare the Hibernate SessionFactory for retrieving Hibernate sessions --&gt;
      &lt;!-- See http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/orm/hibernate3/annotation/AnnotationSessionFactoryBean.html --&gt;                           
      &lt;!-- See http://docs.jboss.org/hibernate/stable/core/api/index.html?org/hibernate/SessionFactory.html --&gt;
      &lt;!-- See http://docs.jboss.org/hibernate/stable/core/api/index.html?org/hibernate/Session.html --&gt;
      &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"
  
                   p:configLocation="${hibernate.config}"
                   p:packagesToScan="com.asman.vote.mypaint"/&gt;
      &lt;!-- p:dataSource-ref="dataSource" --&gt;
      &lt;!-- Declare a datasource that has pooling capabilities--&gt; &lt;!-- &lt;bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
                  destroy-method="close"
                  p:driverClass="${app.jdbc.driverClassName}"
                  p:jdbcUrl="${app.jdbc.url}"
                  p:user="${app.jdbc.username}"
                  p:password="${app.jdbc.password}"
                  p:acquireIncrement="10"
                  p:idleConnectionTestPeriod="60"
                  p:maxPoolSize="100000"
                  p:maxStatements="100"
                  p:minPoolSize="100000" /&gt; --&gt;&lt;bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" 
                  p:sessionFactory-ref="sessionFactory" /&gt;&lt;/beans&gt;
  </code></pre>
  
  <h2>applicationContext.xml:</h2>
  
  <p>
  http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
              <a href="http://www.springframework.org/schema/context" rel="noreferrer">http://www.springframework.org/schema/context</a>
              <a href="http://www.springframework.org/schema/context/spring-context-3.1.xsd" rel="noreferrer">http://www.springframework.org/schema/context/spring-context-3.1.xsd</a>
              <a href="http://www.springframework.org/schema/mvc" rel="noreferrer">http://www.springframework.org/schema/mvc</a> 
              <a href="http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd" rel="noreferrer">http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd</a>">`</p>
  
  <pre><code>&lt;!-- &lt;context:property-placeholder properties-ref="deployProperties" /&gt; --&gt;
  
  &lt;!-- Activates various annotations to be detected in bean classes --&gt;
  &lt;context:annotation-config /&gt;
  
  &lt;!-- Scans the classpath for annotated components that will be auto-registered as Spring beans.
   For example @Controller and @Service. Make sure to set the correct base-package --&gt;
  &lt;context:component-scan base-package="com.asman.vote.mypaint" /&gt;
  
  &lt;!-- Configures the annotation-driven Spring MVC Controller programming model.
  Note that, with Spring 3.0, this tag works in Servlet MVC only!  --&gt;
  &lt;mvc:annotation-driven /&gt; 
  
  &lt;!-- Configure the multipart resolver --&gt;
  &lt;bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"
      p:maxUploadSize="100000000"/&gt;
  
  &lt;mvc:resources mapping="/resources/**" location="/resources/" /&gt; 
  &lt;mvc:interceptors&gt;
  &lt;bean class="org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor"&gt;
      &lt;property name="sessionFactory"&gt;
          &lt;ref local="sessionFactory" /&gt;
      &lt;/property&gt;
  &lt;/bean&gt;&lt;/mvc:interceptors&gt;&lt;!-- Imports logging configuration --&gt;
  &lt;import resource="trace-context.xml"/&gt;
  &lt;import resource="hibernate-context.xml" /&gt; 
  &lt;bean id="deployProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean"
      p:location="/WEB-INF/spring.properties" /&gt;&lt;/beans&gt; 
  </code></pre>
  
  <h2>spring-servlet.xml:</h2>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:p="http://www.springframework.org/schema/p" 
      xsi:schemaLocation="http://www.springframework.org/schema/beans 
              http://www.springframework.org/schema/beans/spring-beans-3.1.xsd"&gt;
  
      &lt;!-- Declare a view resolver --&gt;
      &lt;bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" 
              p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" p:order="1"/&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <h2>trace-context.xml:</h2>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans" 
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xmlns:p="http://www.springframework.org/schema/p" 
          xmlns:aop="http://www.springframework.org/schema/aop"
          xsi:schemaLocation="
              http://www.springframework.org/schema/beans 
              http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
              http://www.springframework.org/schema/aop 
              http://www.springframework.org/schema/aop/spring-aop-3.1.xsd"&gt;`
  
      &lt;!-- For parsing classes with @Aspect annotation --&gt;
      &lt;aop:aspectj-autoproxy/&gt;
  
      &lt;bean id="customizableTraceInterceptor" class="com.asman.vote.mypaint.aop.TraceInterceptor"
          p:enterMessage="Entering $[targetClassShortName].$[methodName]($[arguments])"
          p:exitMessage="Leaving $[targetClassShortName].$[methodName](): $[returnValue]"/&gt;
  
      &lt;aop:config&gt;
        &lt;aop:advisor advice-ref="customizableTraceInterceptor" pointcut="execution(public * com.asman.vote.mypaint.service..*(..))"/&gt;
        &lt;aop:advisor advice-ref="customizableTraceInterceptor" pointcut="execution(public * com.asman.vote.mypaint.controller..*(..))"/&gt;
      &lt;/aop:config&gt;
  
  &lt;/beans&gt;
  </code></pre>