Results 1 to 3 of 3

Thread: Exception withDriverManagerDataSource+JDBCTransactionFactory

  1. #1

    Default Exception withDriverManagerDataSource+JDBCTransactionFactory

    DataSource I configed with "org.springframework.jdbc.datasource.DriverManager DataSource", and TransactionManager configed with "org.springframework.orm.hibernate.HibernateTransa ctionManager",
    and It caused below exception:
    [junit] INFO [main] net.sf.hibernate.transaction.TransactionManagerLoo kupFactory - No TransactionManagerLookup
    configured (in JTA environment, use of process level read-write cache is not recommended)
    [junit] DEBUG [main] org.springframework.jdbc.datasource.DriverManagerD ataSource - Creating new JDBC connection
    to [
    [junit] jdbc:mysql://localhost:3306/test
    [junit] ]
    [junit] DEBUG [main] net.sf.hibernate.util.JDBCExceptionReporter - SQL Exception
    [junit] java.sql.SQLException: No suitable driver
    [junit] at java.sql.DriverManager.getConnection(DriverManager .java:532)
    [junit] at java.sql.DriverManager.getConnection(DriverManager .java:171)
    [junit] at org.springframework.jdbc.datasource.DriverManagerD ataSource.getConnectionFromDriverManager(DriverMan a
    gerDataSource.java:156)
    [junit] at org.springframework.jdbc.datasource.DriverManagerD ataSource.getConnectionFromDriverManager(DriverMan a
    gerDataSource.java:144)
    [junit] at org.springframework.jdbc.datasource.DriverManagerD ataSource.getConnection(DriverManagerDataSource.ja v
    a:132)
    [junit] at org.springframework.orm.hibernate.LocalDataSourceC onnectionProvider.getConnection(LocalDataSourceCon n
    ectionProvider.java:75)
    [junit] at net.sf.hibernate.cfg.SettingsFactory.buildSettings (SettingsFactory.java:84)
    [junit] at net.sf.hibernate.cfg.Configuration.buildSettings(C onfiguration.java:1172)
    [junit] at net.sf.hibernate.cfg.Configuration.buildSessionFac tory(Configuration.java:803)
    [junit] at org.springframework.orm.hibernate.LocalSessionFact oryBean.newSessionFactory(LocalSessionFactoryBean. j
    ava:544)
    [junit] at org.springframework.orm.hibernate.LocalSessionFact oryBean.afterPropertiesSet(LocalSessionFactoryBean .
    java:479)
    [junit] at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.invokeInitMethods(Abstr a
    ctAutowireCapableBeanFactory.java:1072)
    [junit] at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto w
    ireCapableBeanFactory.java:343)
    [junit] at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto w
    ireCapableBeanFactory.java:260)
    [junit] at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:221)
    [junit] at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:145)
    [junit] at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul t
    ListableBeanFactory.java:285)
    [junit] at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja v
    a:317)
    [junit] at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon t
    ext.java:80)
    [junit] at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon t
    ext.java:65)
    [junit] at org.fac.dao.hibernate.BaseDAOTestCase.<clinit>(Bas eDAOTestCase.java:28)
    [junit] at java.lang.Class.forName0(Native Method)
    [junit] at java.lang.Class.forName(Class.java:141)
    [junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnit TestRunner.<init>(JUnitTestRunner.java:237)
    [junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnit TestRunner.<init>(JUnitTestRunner.java:210)
    [junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnit TestRunner.main(JUnitTestRunner.java:532)
    [junit] WARN [main] net.sf.hibernate.util.JDBCExceptionReporter - SQL Error: 0, SQLState: 08001


    Below is my Spring+Hibernate configuration:
    <beans>
    <!--
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    -->
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverM anagerDataSource">

    <property name="driverClassName">

    <value>com.mysql.jdbc.Driver</value>
    <!--
    <value>org.gjt.mm.mysql.Driver</value>
    -->
    </property>
    <property name="url">
    <!--
    <value>
    jdbc:mysql://localhost/test?autoReconnect=true&amp;useUnicode=true&amp;ch aracterEncoding=utf-8
    </value>
    -->
    <value>
    jdbc:mysql://172.16.244.218:3306/test
    </value>
    </property>
    <property name="username">
    <value>test</value>
    </property>
    <property name="password">
    <value>pass</value>
    </property>
    </bean>
    </beans>


    <beans>
    <!-- Hibernate SessionFactory -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSess ionFactoryBean">
    <property name="dataSource"><ref bean="dataSource"/></property>
    <property name="mappingResources">
    <list>
    <!-- <value>org/fac/dao/model/Credence.hbm.xml</value>
    <value>org/fac/dao/model/Department.hbm.xml</value>-->
    </list>
    </property>
    <!-- The property below is commented out b/c it doesn't work when run via
    Ant in Eclipse. It works fine for individual JUnit tests and in IDEA ??
    <property name="mappingJarLocations">
    <list><value>file:dist/appfuse-dao.jar</value></list>
    </property>
    -->
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">net.sf.hibernate.dialect.M ySQLDialect</prop>
    <prop key="transaction.factory_class">net.sf.hibernate.t ransaction.JDBCTransactionFactory</prop>
    <prop key="hibernate.show_sql">true</prop>
    <prop key="hibernate.connection.useUnicode">true</prop>
    <!-- Create/update the database tables automatically when the JVM starts up
    <prop key="hibernate.hbm2ddl.auto">update</prop> -->
    <!-- Turn batching off for better error messages under PostgreSQL
    <prop key="hibernate.jdbc.batch_size">0</prop> -->
    </props>
    </property>
    </bean>

    <!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->

    <bean id="transactionManager" class="org.springframework.orm.hibernate.Hibernate TransactionManager">
    <property name="sessionFactory"><ref local="sessionFactory"/></property>
    </bean>
    <!--
    <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTran sactionManager"/>
    -->
    <!-- Generic DAO - can be used when doing standard CRUD -->
    <bean id="dao" class="org.fac.dao.hibernate.BaseDAOHibernate">
    <property name="sessionFactory"><ref local="sessionFactory"/></property>
    </bean>

    <!-- UserDAO: Hibernate implementation -->
    <bean id="departmentDAO" class="org.fac.dao.hibernate.DepartmentDAOHibernat e">
    <property name="sessionFactory"><ref local="sessionFactory"/></property>
    </bean>

    <!-- Add new DAOs here -->

    </beans>

    <beans>
    <!-- Transaction template for Managers, from:
    http://blog.exis.com/colin/archives/...ons-spring-11/ -->
    <bean id="txProxyTemplate" abstract="true"
    class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean">
    <property name="transactionManager"><ref bean="transactionManager"/></property>
    <property name="transactionAttributes">
    <props>
    <prop key="save*">PROPAGATION_REQUIRED</prop>
    <prop key="remove*">PROPAGATION_REQUIRED</prop>
    <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
    </props>
    </property>
    </bean>

    <!-- Generic manager that can be used to do basic CRUD operations on any objects -->
    <bean id="manager" parent="txProxyTemplate">
    <property name="target">
    <bean class="org.fac.service.impl.BaseManagerImpl">
    <property name="DAO"><ref bean="dao"/></property>
    </bean>
    </property>
    </bean>

    <!-- Transaction declarations for business services. To apply a generic transaction proxy to
    all managers, you might look into using the BeanNameAutoProxyCreator -->
    <bean id="departmentManager" parent="txProxyTemplate">
    <property name="target">
    <bean class="org.fac.service.impl.DepartmentManagerImpl" >
    <property name="departmentDAO"><ref bean="departmentDAO"/></property>
    </bean>
    </property>
    <!-- Override default transaction attributes b/c of LoginCookie methods -->
    <property name="transactionAttributes">
    <props>
    <prop key="save*">PROPAGATION_REQUIRED,-UserExistsException</prop>
    <prop key="remove*">PROPAGATION_REQUIRED</prop>
    <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
    </props>
    </property>
    </bean>

    <!-- Add new Managers here -->
    </beans>

  2. #2
    Join Date
    Aug 2004
    Location
    Linz, Austria
    Posts
    391

    Default

    That exception simply indicates that your JDBC URL cannot be resolved against any of the registered JDBC drivers. Double check your driver and URL setup: The driver obviously has been found (else you'll get a ClassNotFoundException), so play with the URL - for example, remove all appended parameters and see whether it works then.

    This problem is not specific to Spring - it's simply your JDBC setup that doesn't work.

    BTW, note that Spring's DriverManagerDataSource does not pool connections. Consider using Commons DBCP's BasicDataSource or C3P0's ComboPooledDataSource for a true connection pool, as direct replacement.

    Juergen

  3. #3

    Default

    Thanks to Juergen's reply!

    and another problem confused me is the debug info as below:
    [junit] INFO [main] net.sf.hibernate.transaction.TransactionManagerLoo kupFactory - No TransactionManagerLookup
    configured (in JTA environment, use of process level read-write cache is not recommended)

    For I used org.springframework.orm.hibernate.HibernateTransac tionManager instead of org.springframework.transaction.jta.JtaTransaction Manager, why it said "JTA environment"?

Similar Threads

  1. Replies: 3
    Last Post: Oct 5th, 2005, 08:39 AM
  2. Context initialization failed
    By kanonmicke in forum Container
    Replies: 7
    Last Post: Sep 29th, 2005, 12:35 AM
  3. Odd behaviour when injecting TransactionTemplate
    By damon311 in forum Container
    Replies: 3
    Last Post: Jul 23rd, 2005, 11:21 AM
  4. Replies: 0
    Last Post: Jul 11th, 2005, 05:49 PM
  5. Replies: 3
    Last Post: Nov 8th, 2004, 07:30 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •