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&useUnicode=true&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>


Reply With Quote