Quantcast
Channel: Spring Community Forums - Data
Viewing all articles
Browse latest Browse all 297

CannotCreateTransactionException - Could not open Hibernate Session for transaction

$
0
0
Hey guys,

I've been facing this exception:
HTML Code:

SEVERE: Servlet.service() for servlet [applicationContext] in context with path [/ArmagedomSeguros] threw exception [Request processing failed; nested exception is org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is java.lang.UnsupportedOperationException: Not supported by BasicDataSource] with root cause
java.lang.UnsupportedOperationException: Not supported by BasicDataSource

I tried to google it, but I didn't find the solution yet.

He is my environment:

ApplicationContext
Code:

<beans xmlns="http://www.springframework.org/schema/beans"
                          xmlns:context="http://www.springframework.org/schema/context"
                          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                          xmlns:mvc="http://www.springframework.org/schema/mvc"
                          xmlns:p="http://www.springframework.org/schema/p"
                          xmlns:tx="http://www.springframework.org/schema/tx"
                          xsi:schemaLocation="
                  http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <!-- Enables the Spring MVC @Controller programming model -->
    <mvc:annotation-driven />
    <!-- Enables the @Autowire -->
    <context:annotation-config />
   
    <!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
        <mvc:resources mapping="/resources/**" location="/resources/" />
       
        <!-- @Controller, @Service, @Configuration, etc. -->
    <context:component-scan base-package="armagedom.controller"/> 
    <context:component-scan base-package="armagedom.service"/>
   
    <!--This tag allows for mapping the DispatcherServlet to "/" (all extensions etc)-->
        <mvc:default-servlet-handler/>
     
        <!-- RESOLVE A VIEW NAME -->
        <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="prefix" value="/WEB-INF/views/" />
            <property name="suffix" value=".jsp" />
          </bean>
         
        <import resource="database/dataSourceContext.xml"/>
        <import resource="database/persistenceContext.xml"/>
       
        <tx:annotation-driven transaction-manager="transactionManager" />       
   
          <bean id = "transactionManager" class = "org.springframework.orm.hibernate4.HibernateTransactionManager">
            <property name = "sessionFactory" ref = "sessionFactory" />
        </bean>
</beans>

dataSourceContext
Code:

<beans xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://www.springframework.org/schema/beans">
       
       
        <!-- Pointing to mine MySQL instance  -->
        <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://localhost:3306/armagedomdb" />
            <property name="username" value="root" />
            <property name="password" value="admin" />
          </bean>
</beans>

persistenceContext
Code:

<beans xmlns="http://www.springframework.org/schema/beans"
                          xmlns:context="http://www.springframework.org/schema/context"
                          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                          xsi:schemaLocation="
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
       
        <context:component-scan base-package="armagedom.dao"/>
       
        <!-- Hibernate session factory : create sessions to interact with the database -->
          <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
            <property name="dataSource" ref="dataSource"></property>
            <property name="hibernateProperties">
                      <props>
                        <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
                        <prop key="hibernate.show_sql">true</prop>
                      </props>
                  </property>
            <property name="packagesToScan" value="armagedom.entities" />
    </bean>         
</beans>

I have no changes in context's file Tomcat7

Thanks in advance guys ....

Viewing all articles
Browse latest Browse all 297

Trending Articles