Spring集成Hibernate4报不能打开连接

错误信息:
org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.GenericJDBCException: Could not open connection
at org.springframework.orm.hibernate4.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:544)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:373)
at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:427)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:276)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208)
at com.sun.proxy.$Proxy7.addStudent(Unknown Source)
at action.StudentAction.execute(StudentAction.java:22)
at test.RunTest.main(RunTest.java:34)
Caused by: org.hibernate.exception.GenericJDBCException: Could not open connection
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:124)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:109)
at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:221)
at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.getConnection(LogicalConnectionImpl.java:157)
at org.hibernate.internal.SessionImpl.connection(SessionImpl.java:427)
at org.springframework.orm.hibernate4.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:450)
... 9 more
Caused by: java.sql.SQLException: 调用中无效的参数
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:113)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:147)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:209)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:236)
at oracle.jdbc.driver.PhysicalConnection.(PhysicalConnection.java:454)
at oracle.jdbc.driver.T4CConnection.(T4CConnection.java:165)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:802)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:153)
at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriver(DriverManagerDataSource.java:144)
at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnectionFromDriver(AbstractDriverBasedDataSource.java:155)
at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnection(AbstractDriverBasedDataSource.java:130)
at org.hibernate.service.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:141)
at org.hibernate.internal.AbstractSessionImpl$NonContextualJdbcConnectionAccess.obtainConnection(AbstractSessionImpl.java:301)
at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:214)
... 12 more

配置文件:
<?xml version="1.0" encoding="UTF-8"?>
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
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.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd">

<context:component-scan base-package="entity"></context:component-scan> 

 <bean name="prop" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
    <list>
        <value>classpath:datasource.properties</value>
    </list>

    </property>
 </bean> 

       <property name="url"><value>jdbc:oracle:thin:@localhost:1521:orcl</value></property>
       <property name="username" value="lei" />
    <property name="password" value="lei" />
    <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
</bean>


<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
 <property name="dataSource"><ref bean="dataSource"></ref></property>
</bean>


<!--hibernate.cfg.xml -->




org.hibernate.dialect.Oracle10gDialect
true



<!-- 事务管理器-->
class="org.springframework.orm.hibernate4.HibernateTransactionManager">

<!-- 事务代理 -->
<bean id="transactionBase"  
        class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"  
        lazy-init="true" abstract="true">  
    <!-- 配置事务管理器 -->  
    <property name="transactionManager" ref="transactionManager" />  
    <!-- 配置事务属性 -->  
    <property name="transactionAttributes">  
        <props>  
            <prop key="update*">PROPAGATION_REQUIRED,-Exception</prop> 
            <prop key="delete*">PROPAGATION_REQUIRED,-Exception</prop>   
            <prop key="add*">PROPAGATION_REQUIRED,-Exception</prop>
        </props>  
    </property>  
</bean>    

<!-- 配置DAO -->
  <bean id="searchDao" class="dao.SearchDao">
     <property name="sessionFactory" ref="sessionFactory" /> 
  <!--    <property name="jdbcTemplate" ref="jdbcTemplate" />  -->  
</bean>

<bean id="updateDao" class="dao.UpdateDao">
   <property name="sessionFactory" ref="sessionFactory" /> 
</bean>



<!-- 配置Service -->
  <bean id="studentServiceTX" class ="serviceImpl.StudentServiceImpl" >  
    <property name="searchDao" ref="searchDao" />   
    <property name="updateDao" ref="updateDao" />           
</bean>

<bean id="studentService" parent="transactionBase" >  
    <property name="target" ref="studentServiceTX" />                 
</bean>  

 <!-- <bean id="studentService" class ="serviceImpl.StudentServiceImpl" >  
    <property name="searchDao" ref="searchDao" />                    
</bean>    -->

<!-- 配置Action -->
<bean id="studentAction" class ="action.StudentAction" >  
    <property name="studentService" ref="studentService" />                    
</bean>

Dao代码:
package dao;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.jdbc.core.JdbcTemplate;
import org.hibernate.Transaction;
import org.springframework.orm.hibernate4.HibernateTemplate;
import org.springframework.orm.hibernate4.support.HibernateDaoSupport;

import entity.StudentInfo;

public class SearchDao{

private JdbcTemplate jdbcTemplate;

private SessionFactory sessionFactory;


public SessionFactory getSessionFactory() {
    return sessionFactory;
}

public void setSessionFactory(SessionFactory sessionFactory) {
    this.sessionFactory = sessionFactory;
}

public JdbcTemplate getJdbcTemplate() {
    return jdbcTemplate;
}

public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
    this.jdbcTemplate = jdbcTemplate;
}

public SearchDao(){
    super();
}

@SuppressWarnings("unchecked")
public void addStudent(StudentInfo student)throws Exception {
     HibernateTemplate hibernateTemplate = new HibernateTemplate(this.sessionFactory);
     hibernateTemplate.save(student);

}

}

请教各位大神

1个回答

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问