问题描述
在我的应用程序中,我有一个模块用于为用户搜索数据库并在jsp中的表中显示其信息。我只是在我的应用程序中设置了Spring Security。我能够从登录页面连接到数据库,但由于某些原因,我的DAO的CRUD操作(在这种情况下,搜索)没有任何作用。
谢谢,请告诉我是否可以提供更多信息。
以下是我的堆栈跟踪信息。
org.springframework.web.util.NestedServletException:请求处理失败;嵌套异常是org.springframework.transaction.CannotCreateTransactionException:无法打开Hibernate Session进行事务处理;嵌套异常是org.hibernate.exception.GenericJDBCException:无法打开连接
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:656)
org.springframework.web.servlet.FrameworkServlet。 doPost(FrameworkServlet.java:560)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
...
org.springframework.transaction.CannotCreateTransactionException:无法为事务打开Hibernate Session;嵌套异常是org.hibernate.exception.GenericJDBCException:无法打开连接
org.springframework.orm.hibernate3.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:596)
org.springframework.transaction.support.AbstractPlatformTransactionManager。 getTransaction(AbstractPlatformTransactionManager.java:371)
org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:335)
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
org.springframework.aop.framework.J dkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
$ Proxy8.searchEntity(未知源代码)
arlua.controller.SearchUserController.mySearchMethod(SearchUserController.java:35)
sun.reflect.NativeMethodAccessorImpl。 invoke0(本地方法)
sun.reflect.NativeMethodAccessorImpl.invoke(未知源)
sun.reflect.DelegatingMethodAccessorImpl.invoke(未知源
...
org.hibernate.exception.GenericJDBCException:无法打开连接
org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:140)
org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter。 java:128)
org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:52)
org。 hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:449)
org .hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167)
org.hibernate.jdbc.BorrowedConnectionProxy.invoke(BorrowedConnectionProxy.java:74)
$ Proxy14.getTransactionIsolation(Unknown Source)
...
java.sql.SQLException:调用中的无效参数
oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:208)
oracle.jdbc.driver.T4CConnection.logon( T4CConnection.java:236)
oracle.jdbc.driver.PhysicalConnection。< init>(PhysicalConnection.java:414)
oracle.jdbc.driver.T4CConnection。< init>(T4CConnection.java:
oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)
oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:801)
java.sql.DriverManager.getConnection(未知源)
java.sql.DriverManager.getConnection(未知源)
org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:173)
org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriver(DriverManagerDataSource.java:164)
org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnectionFromDriver(AbstractDriverBasedDataSource.java:149)
组织。 springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnection(AbstractDriverBasedDataSource.java:119)
org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.getConnection(LocalDataSourceConnectionProvider.java:81)
org.hibernate.jdbc.ConnectionManager。 openConnection(ConnectionManager.java:446)
org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167)
org.hibernate.jdbc.BorrowedConnectionProxy.invoke(BorrowedConnectionProxy.java:74)
$ Proxy14.getTransactionIsolation(来源不明)
org.springframework.jdbc.datasource.DataSourceUtils.prepareConnectionForTransaction(DataSourceUtils.java :190)
org.springframework.orm.hibernate3.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:508)
org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371)
org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:335)
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:105)
org.springframework.aop .framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
org.springframework.aop.interceptor.ExposeInvocation Interceptor.invoke(ExposeInvocationInterceptor.java:89)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy。 java:202)
$ Proxy8.searchEntity(未知源代码)
arlua.controller.SearchUserController.mySearchMethod(SearchUserController.java:35)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(未知源)
sun.reflect.DelegatingMethodAccessorImpl.invoke(未知源)
java.lang.reflect.Method.invoke(未知源)
org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:426)
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:414)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
组织。 springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
org.springframework.web.servlet。 FrameworkServlet.doPost(FrameworkServlet.java:560)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
$ org.springframework.security.web.FilterChainProxy VirtualFilterChain.doFilter(FilterChainProxy.java:368)
org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)
org.springframework.security.web.access.intercept.Filte rSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
$ org.springframework.security.web.FilterChainProxy VirtualFilterChain.doFilter(FilterChainProxy.java:380)
org.springframework.security.web.access.ExceptionTranslationFilter。的doFilter(ExceptionTranslationFilter.java:97)
$ org.springframework.security.web.FilterChainProxy VirtualFilterChain.doFilter(FilterChainProxy.java:380)
org.springframework.security.web.session.SessionManagementFilter.doFilter( SessionManagementFilter.java:100)
$ org.springframework.security.web.FilterChainProxy VirtualFilterChain.doFilter(FilterChainProxy.java:380)
org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter。 java:78)
org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:380)
org.springframework.security.web.servletapi.SecurityContextHolder AwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:380)
org.springframework.security.web.savedrequest.RequestCacheAwareFilter。 doFilter(RequestCacheAwareFilter.java:35)
org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:380)
org.springframework.security.web.authentication.www.BasicAuthenticationFilter。的doFilter(BasicAuthenticationFilter.java:177)
$ org.springframework.security.web.FilterChainProxy VirtualFilterChain.doFilter(FilterChainProxy.java:380)
org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter。 doFilter(DefaultLoginPageGeneratingFilter.java:91)
org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:380)
org.springframework.security。 web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:187)
$ org.springframework.security.web.FilterChainProxy VirtualFilterChain.doFilter(FilterChainProxy.java:380)
org.springframework.security.web。 (LogoutFilter.java:105)
org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:380)
org.springframework.security.web。 context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:79)
$ org.springframework.security.web.FilterChainProxy VirtualFilterChain.doFilter(FilterChainProxy.java:380)
org.springframework.security.web.FilterChainProxy。 doFilter(FilterChainProxy.java:169)
org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
org.springframework.web.filter.DelegatingFilterProxy.d oFilter(DelegatingFilterProxy.java:167)
SearchUserController类
package arlua.controller;
import java.util.List;
导入arlua.dao.TableEntityFetchDao;
导入arlua.exception.ImproperUserSearchException;
导入arlua.exception.SearchStringTooShortException;
导入arlua.helper.BuildUserTables;
导入arlua.service.SearchCriteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;
@Controller
@SessionAttributes
public class SearchUserController {
$ b $ private @Autowired @Qualifier(userInfoDaoImpl)TableEntityFetchDao userInfoDao;
列表<?> searchList;
字符串错误;
@RequestMapping(value =/ search_user,method = RequestMethod.POST)
public String mySearchMethod(@ModelAttribute(search_criteria)SearchCriteria search){
error =;
try {
if(search.getInput()!= null)
searchList = userInfoDao.searchEntity(search.getInput());
}
catch(SearchStringTooShortException e1){
error =搜索条件太短,要更具体。
}
catch(ImproperUserSearchException e2){
error =指定ID或名字和姓氏。;
}
返回redirect:search_user;
}
@RequestMapping(/ search_user)
public ModelAndView mySuccessMethod(){
ModelAndView model = new ModelAndView(search_user);
$ b $ if(searchList!= null){
if(searchList.size()== 0)
error =搜索没有返回结果。
else
model.addObject(searchTable,BuildUserTables.buildSearch(searchList));
}
返回模型;
$ bUserInfoDaoImpl class strong>
package arlua.dao.impl;
导入arlua.dao.TableEntityFetchDao;
导入arlua.exception.ImproperUserSearchException;
导入arlua.exception.SearchStringTooShortException;
导入arlua.tables.UserInfoTable;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
public class UserInfoDaoImpl implements TableEntityFetchDao {
@Autowired
private SessionFactory sessionFactory;
public void setSessionFactory(SessionFactory sessionFactory){
this.sessionFactory = sessionFactory;
}
public void saveEntity(Object userInfo){
this.sessionFactory.getCurrentSession()。save((UserInfoTable)userInfo);
}
public UserInfoTable getEntity(Object user_id){
return(UserInfoTable)this.sessionFactory.getCurrentSession()。
get(UserInfoTable.class,(String)user_id);
}
public void updateEntity(Object userInfo){
this.sessionFactory.getCurrentSession()。update((UserInfoTable)userInfo);
public void deleteEntity(Object userInfo){
this.sessionFactory.getCurrentSession()。delete((UserInfoTable)userInfo);
}
public List<?> getAllEntities(){
return this.sessionFactory.getCurrentSession()。createQuery
(FROM UserInfoTable)。list();
}
public List<?> searchEntity(String search)抛出SearchStringTooShortException,ImproperUserSearchException {
//此搜索支持输入用户的seid或第一个和最后一个名称。
if(search.length() throw new SearchStringTooShortException();
}
Session s = this.sessionFactory.getCurrentSession();
列表<?> searchList = new ArrayList();
//搜索具有匹配SEID的相似用户。
if(search.matches(^ [a-zA-Z0-9] * [0-9] + [a-zA-Z0-9] * $)){
searchList = s .createQuery
//(FROM UserInfoTable)。list();
(FROM UserInfoTable WHERE UPPER(user_id)LIKE UPPER('%+ search +%'))。list();
}
//搜索具有匹配名字和姓氏的相似用户。
//如果搜索包含2个以上的参数,则会抛出异常。
else if(search.length()> = 3){
String [] searchParts = search.split();
if(searchParts.length!= 2)
throw new ImproperUserSearchException();
searchList = s.createQuery $ b $(FROM UserInfoTable WHERE UPPER(first_name)LIKE UPPER('%+ searchParts [0] +%')+
AND UPPER(last_name) LIKE UPPER('%'+ searchParts [1] +%'))。list();
}
else {
抛出新的ImproperUserSearchException();
}
返回searchList;
application-context.xml
<?xml version =1.0encoding =UTF-8?>
< beans xmlns =http://www.springframework.org/schema/beans
xmlns:xsi =http://www.w3.org/2001/XMLSchema-instance
xmlns:aop =http://www.springframework.org/schema/aop
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/aop
http://www.springframework.org/schema/aop/spring-aop- 3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd\">
< context:annotation-config />
< bean id =serverDatasource
class =org.springframework.jdbc.datasource.DriverManagerDataSource>
< property name =driverClassName>
< value> oracle.jdbc.driver.OracleDriver< / value>
< / property>
< property name =url>
<值>网址< /值>
< / property>
< / bean>
< bean id =dataSourceclass =org.springframework.jdbc.datasource.UserCredentialsDataSourceAdapter>
< property name =targetDataSourceref =serverDatasource/>
< property name =password>< value> unknown< / value>< / property>
< / bean>
<! -
< bean id =propertyPlaceholderConfigurer
class =org.springframework.beans.factory.config.PropertyPlaceholderConfigurer>
< property name =systemPropertiesModeNamevalue =SYSTEM_PROPERTIES_MODE_OVERRIDE/>
< property name =ignoreUnresolvablePlaceholdersvalue =true/>
< / bean>
- >
< bean id =mySessionFactory
class =org.springframework.orm.hibernate3.LocalSessionFactoryBean>
< property name =mappingLocations>
< list>
<值> WEB-INF / mapping / user_info.hbm.xml< /值>
<值> WEB-INF / mapping / login.hbm.xml< /值>
<值> WEB-INF / mapping / linked_accounts.hbm.xml< /值>
<值> WEB-INF / mapping / application_instance.hbm.xml< /值>
< / list>
< / property>
< property name =hibernateProperties>
<道具>
< prop key =hibernate.dialect> org.hibernate.dialect.OracleDialect< / prop>
< prop key =hibernate.hbm2ddl.auto> update< / prop>
< /道具>
< / property>
< property name =dataSourceref =serverDatasource/>
< / bean>
< bean id =userInfoDaoImplclass =arlua.dao.impl.UserInfoDaoImpl>
< property name =sessionFactoryref =mySessionFactory/>
< / bean>
< bean id =loginDaoImplclass =arlua.dao.impl.LoginDaoImpl>
< property name =sessionFactoryref =mySessionFactory/>
< / bean>
< bean id =linkedAccountsDaoImplclass =arlua.dao.impl.LinkedAccountsDaoImpl>
< property name =sessionFactoryref =mySessionFactory/>
< / bean>
< bean id =applicationInstanceDaoImplclass =arlua.dao.impl.ApplicationInstanceDaoImpl>
< property name =sessionFactoryref =mySessionFactory/>
< / bean>
< bean id =roleDaoImplclass =arlua.dao.impl.RoleDaoImpl>
< property name =sessionFactoryref =mySessionFactory/>
< / bean>
< bean id =applicationApprovalDaoImplclass =arlua.dao.impl.ApplicationApprovalDaoImpl>
< property name =sessionFactoryref =mySessionFactory/>
< / bean>
< bean id =userDaoImplclass =arlua.dao.impl.UserDaoImpl/>
< bean id =myTransactionManager
class =org.springframework.orm.hibernate3.HibernateTransactionManager>
< property name =sessionFactoryref =mySessionFactory/>
< / bean>
< aop:config>
< / aop:config>
< tx:advice id =txAdvicetransaction-manager =myTransactionManager>
< tx:attributes>
< tx:method name =saveEntity
propagation =REQUIRES_NEW
isolation =READ_COMMITTED
rollback-for =Exception/>
< tx:方法名称=updateEntity
propagation =REQUIRES_NEW
isolation =READ_COMMITTED
rollback-for =Exception/>
< tx:method name =getEntity
propagation =REQUIRES_NEW
isolation =READ_COMMITTED
rollback-for =Exception/>
< tx:method name =getAllEntities
propagation =REQUIRES_NEW
isolation =READ_COMMITTED
rollback-for =Exception/>
< tx:method name =searchEntity
propagation =REQUIRES_NEW
isolation =READ_COMMITTED
rollback-for =Exception/>
< / tx:属性>
< / tx:advice>
< / beans>
解决方案java.sql.SQLException :调用中的无效参数意味着连接数据库时遇到URL / auth问题时的问题:查看堆栈跟踪您没有通过 UserCredentialsDataSourceAdapter code> id =datasource)但使用 DriverManagerDataSource ( id =serverDatasource$ c
在sessionFactory bean创建线程中:
< property name =dataSourceref =dataSource/>
而不是:
< property name =dataSourceref =serverDatasource/>In my application, I have a module that is designed to search a database for users and display their information in a table inside a jsp. I just setup Spring Security inside my application. I was able to make a connection to the database from the login page, though for some reason none of my DAO's CRUD operations (in this case, the search) are working.
Thanks, and please let me know if I can provide any more information.
Here is most of my stack trace.
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.GenericJDBCException: Cannot open connection org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:656) org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560) javax.servlet.http.HttpServlet.service(HttpServlet.java:637) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) ... org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.GenericJDBCException: Cannot open connection org.springframework.orm.hibernate3.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:596) org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371) org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:335) org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:105) org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89) org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202) $Proxy8.searchEntity(Unknown Source) arlua.controller.SearchUserController.mySearchMethod(SearchUserController.java:35) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source ... org.hibernate.exception.GenericJDBCException: Cannot open connection org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:140) org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:128) org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66) org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:52) org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:449) org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167) org.hibernate.jdbc.BorrowedConnectionProxy.invoke(BorrowedConnectionProxy.java:74) $Proxy14.getTransactionIsolation(Unknown Source) ... java.sql.SQLException: invalid arguments in call oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112) oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146) oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:208) oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:236) oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:414) oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:165) oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35) oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:801) java.sql.DriverManager.getConnection(Unknown Source) java.sql.DriverManager.getConnection(Unknown Source) org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:173) org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriver(DriverManagerDataSource.java:164) org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnectionFromDriver(AbstractDriverBasedDataSource.java:149) org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnection(AbstractDriverBasedDataSource.java:119) org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.getConnection(LocalDataSourceConnectionProvider.java:81) org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446) org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167) org.hibernate.jdbc.BorrowedConnectionProxy.invoke(BorrowedConnectionProxy.java:74) $Proxy14.getTransactionIsolation(Unknown Source) org.springframework.jdbc.datasource.DataSourceUtils.prepareConnectionForTransaction(DataSourceUtils.java:190) org.springframework.orm.hibernate3.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:508) org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371) org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:335) org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:105) org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89) org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202) $Proxy8.searchEntity(Unknown Source) arlua.controller.SearchUserController.mySearchMethod(SearchUserController.java:35) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) java.lang.reflect.Method.invoke(Unknown Source) org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176) org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:426) org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:414) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644) org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560) javax.servlet.http.HttpServlet.service(HttpServlet.java:637) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:368) org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109) org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380) org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:97) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380) org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:100) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380) org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:78) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380) org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380) org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:35) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380) org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:177) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380) org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter.doFilter(DefaultLoginPageGeneratingFilter.java:91) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380) org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:187) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380) org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380) org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:79) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380) org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:169) org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237) org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)SearchUserController class
package arlua.controller; import java.util.List; import arlua.dao.TableEntityFetchDao; import arlua.exception.ImproperUserSearchException; import arlua.exception.SearchStringTooShortException; import arlua.helper.BuildUserTables; import arlua.service.SearchCriteria; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.SessionAttributes; import org.springframework.web.servlet.ModelAndView; @Controller @SessionAttributes public class SearchUserController { private @Autowired @Qualifier("userInfoDaoImpl") TableEntityFetchDao userInfoDao; List<?> searchList; String error; @RequestMapping(value = "/search_user", method = RequestMethod.POST) public String mySearchMethod(@ModelAttribute("search_criteria") SearchCriteria search){ error = ""; try{ if(search.getInput() != null) searchList = userInfoDao.searchEntity(search.getInput()); } catch(SearchStringTooShortException e1){ error = "Search criteria is too short. Be more specific."; } catch(ImproperUserSearchException e2){ error = "Specify either an Id or first and last name."; } return "redirect:search_user"; } @RequestMapping("/search_user") public ModelAndView mySuccessMethod(){ ModelAndView model = new ModelAndView("search_user"); if(searchList != null){ if(searchList.size() == 0) error = "Search returned no results."; else model.addObject("searchTable", BuildUserTables.buildSearch(searchList)); } return model; } }UserInfoDaoImpl class
package arlua.dao.impl; import arlua.dao.TableEntityFetchDao; import arlua.exception.ImproperUserSearchException; import arlua.exception.SearchStringTooShortException; import arlua.tables.UserInfoTable; import java.util.ArrayList; import java.util.List; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.springframework.beans.factory.annotation.Autowired; public class UserInfoDaoImpl implements TableEntityFetchDao{ @Autowired private SessionFactory sessionFactory; public void setSessionFactory(SessionFactory sessionFactory){ this.sessionFactory = sessionFactory; } public void saveEntity(Object userInfo) { this.sessionFactory.getCurrentSession().save((UserInfoTable)userInfo); } public UserInfoTable getEntity(Object user_id) { return (UserInfoTable)this.sessionFactory.getCurrentSession(). get(UserInfoTable.class, (String)user_id); } public void updateEntity(Object userInfo) { this.sessionFactory.getCurrentSession().update((UserInfoTable)userInfo); } public void deleteEntity(Object userInfo) { this.sessionFactory.getCurrentSession().delete((UserInfoTable)userInfo); } public List<?> getAllEntities() { return this.sessionFactory.getCurrentSession().createQuery ("FROM UserInfoTable").list(); } public List<?> searchEntity(String search) throws SearchStringTooShortException, ImproperUserSearchException{ //This search supports input of a user's seid OR a first and last name. if(search.length() < 3){ throw new SearchStringTooShortException(); } Session s = this.sessionFactory.getCurrentSession(); List<?> searchList = new ArrayList(); //Searches for similar users with matching SEIDs. if(search.matches("^[a-zA-Z0-9]*[0-9]+[a-zA-Z0-9]*$")){ searchList = s.createQuery //("FROM UserInfoTable").list(); ("FROM UserInfoTable WHERE UPPER(user_id) LIKE UPPER('%" + search + "%')").list(); } //Searches for similar users with a matching first and last name. //If the search contains more than 2 arguments, an exception will be thrown. else if(search.length() >= 3){ String[] searchParts = search.split(" "); if(searchParts.length != 2) throw new ImproperUserSearchException(); searchList = s.createQuery ("FROM UserInfoTable WHERE UPPER(first_name) LIKE UPPER('%" + searchParts[0] + "%') " + "AND UPPER(last_name) LIKE UPPER('%" + searchParts[1] + "%')").list(); } else{ throw new ImproperUserSearchException(); } return searchList; } }application-context.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" 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/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <context:annotation-config /> <bean id="serverDatasource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName"> <value>oracle.jdbc.driver.OracleDriver</value> </property> <property name="url"> <value>url</value> </property> </bean> <bean id="dataSource" class="org.springframework.jdbc.datasource.UserCredentialsDataSourceAdapter"> <property name="targetDataSource" ref="serverDatasource"/> <property name="username"><value>unknown</value></property> <property name="password"><value>unknown</value></property> </bean> <!-- <bean id="propertyPlaceholderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" /> <property name="ignoreUnresolvablePlaceholders" value="true"/> </bean> --> <bean id="mySessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="mappingLocations"> <list> <value>WEB-INF/mapping/user_info.hbm.xml</value> <value>WEB-INF/mapping/login.hbm.xml</value> <value>WEB-INF/mapping/linked_accounts.hbm.xml</value> <value>WEB-INF/mapping/application_instance.hbm.xml</value> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop> <prop key="hibernate.hbm2ddl.auto">update</prop> </props> </property> <property name="dataSource" ref="serverDatasource"/> </bean> <bean id = "userInfoDaoImpl" class="arlua.dao.impl.UserInfoDaoImpl"> <property name="sessionFactory" ref="mySessionFactory"/> </bean> <bean id = "loginDaoImpl" class="arlua.dao.impl.LoginDaoImpl"> <property name="sessionFactory" ref="mySessionFactory"/> </bean> <bean id = "linkedAccountsDaoImpl" class="arlua.dao.impl.LinkedAccountsDaoImpl"> <property name="sessionFactory" ref="mySessionFactory"/> </bean> <bean id = "applicationInstanceDaoImpl" class="arlua.dao.impl.ApplicationInstanceDaoImpl"> <property name="sessionFactory" ref="mySessionFactory"/> </bean> <bean id = "roleDaoImpl" class="arlua.dao.impl.RoleDaoImpl"> <property name="sessionFactory" ref="mySessionFactory"/> </bean> <bean id = "applicationApprovalDaoImpl" class="arlua.dao.impl.ApplicationApprovalDaoImpl"> <property name="sessionFactory" ref="mySessionFactory"/> </bean> <bean id = "userDaoImpl" class="arlua.dao.impl.UserDaoImpl"/> <!-- ************* TRANSACTION MANAGEMENT USING AOP **************** --> <bean id="myTransactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="mySessionFactory"/> </bean> <aop:config> <aop:pointcut id="allMethods" expression="execution(* arlua.dao.TableEntityFetchDao.*(..))"/> <aop:advisor advice-ref="txAdvice" pointcut-ref="allMethods"/> </aop:config> <tx:advice id="txAdvice" transaction-manager="myTransactionManager"> <tx:attributes> <tx:method name="saveEntity" propagation = "REQUIRES_NEW" isolation = "READ_COMMITTED" rollback-for = "Exception"/> <tx:method name="updateEntity" propagation = "REQUIRES_NEW" isolation = "READ_COMMITTED" rollback-for = "Exception"/> <tx:method name="getEntity" propagation = "REQUIRES_NEW" isolation = "READ_COMMITTED" rollback-for = "Exception"/> <tx:method name="getAllEntities" propagation = "REQUIRES_NEW" isolation = "READ_COMMITTED" rollback-for = "Exception"/> <tx:method name="searchEntity" propagation = "REQUIRES_NEW" isolation = "READ_COMMITTED" rollback-for = "Exception"/> </tx:attributes> </tx:advice> </beans>解决方案java.sql.SQLException: invalid arguments in call means problem while connect to database do to URL/auth issues: looking stacktrace your are not getting connection via UserCredentialsDataSourceAdapter (your id="datasource") but using DriverManagerDataSource (id="serverDatasource"): in few word your are trying to connect without using user/password.
In sessionFactory bean creating wire:
<property name="dataSource" ref="dataSource"/>
instead of:
<property name="dataSource" ref="serverDatasource"/>这篇关于无法打开Hibernate Session进行交易/无法打开连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!