ORA-01017 从 TOMCAT 迁移到 IBM Websphere 时 Username/Password 无效

ORA-01017 Invalid Username/Password when migrating from TOMCAT to IBM Websphere

我们正在将 war 文件从 TOMCAT 迁移到 IBM Websphere 8.5.5 应用程序服务器。它在 TOMCAT 上运行良好,但在 IBM WAS 中抛出 "invalid username/password logon denied" 错误。我在 web.xml 和 persistence.xml 中配置了正确的数据源。我还与我们的服务器管理员核实过,他确认数据源是正确的并且能够使用它成功地进行测试。不确定我是否需要 add/change IBM WAAS 8.5.5 的任何配置。请指教

web.xml

<resource-ref>
  <description>Example datasource</description>
  <res-ref-name>jdbc/exampleDS</res-ref-name>
  <res-type>javax.sql.DataSource</res-type>
  <res-auth>Container</res-auth>
  <res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>

persistence.xml

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
         version="2.0">
<persistence-unit name="sample">
  <provider>org.hibernate.ejb.HibernatePersistence</provider>
  <jta-data-source>jdbc/exampleDS</jta-data-source>
  <class>com.hibernate.test.Example</class>
  <properties>
     <property name="hibernate.default_schema" value="XXXXXX"/>
     <property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
     <property name="hibernate.show_sql" value="true"/>
     <property name="hibernate.format_sql" value="true"/>
     <property name="hibernate.hbm2ddl.auto" value="update"/>
   </properties>
  </persistence-unit>
</persistence>

项目结构:

ExampleRestService.war
  - WEB-INF/classes
    - com/hibernate/test/Resource
    - com/hibernate/test/Application
    - log4j.properties
  - WEB-INF/lib
    - hibernate-commons-annotations-4.0.1.Final.jar
    - hibernate-core-4.1.1.Final.jar
    - hibernate-entitymanager-4.1.1.Final.jar
    - hibernate-jpa-2.0-api-1.0.1.Final.jar
    - jackson-core-asl-1.7.1.jar
    - jackson-jaxrs-1.7.1.jar
    - jackson-mapper-asl-1.7.1.jar
    - jackson-xc-1.7.1.jar
    - javassist-3.15.0.GA.jar
    - jboss-transaction-api_1.1_spec-1.0.0.Final.jar
    - jersey-apache-client-1.8.jar
    - jersey-atom-abdera-1.8.jar
    - jersey-client-1.8.jar
    - jersey-core-1.8.jar
    - jersey-guice-1.8.jar
    - jersey-multipart-1.8.jar
    - jersey-server-1.8.jar
    - jersey-simple-server-1.8.jar
    - jersey-spring-1.8.jar
    - jettison-1.2.jar
    - jettison-1.1.jar
    - jsr173_api.jar
    - jsr311-api-1.1.1.jar
    - ojdbc6.jar
    - postgresql-8.3-603.jdbc3.jar
    - ExampleLibrary.jar
  - ExampleLibrary.jar/META-INF/Persistence.xml
  - web/WEB-INF/web.xml

更新: 添加 stacktrcae

12/14/16 09:19:50.916    000000D2    com.ibm.ws.webcontainer.webapp    SEVERE    com.ibm.ws.webcontainer.webapp.WebApp logServletError SRVE0293E: [Servlet Error]-[ServletAdaptor]: javax.persistence.QueryTimeoutException: Could not open connection
    at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1322)
    at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1288)
    at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:1370)
    at org.hibernate.ejb.TransactionImpl.begin(TransactionImpl.java:60)
    at com.dd.core.RequestHandler.handleRequest(RequestHandler.java:89)
    at com.hibernate.test.Resource.invokeExampleService(Resource.java:75)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:95)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
    at java.lang.reflect.Method.invoke(Method.java:507)
    at com.sun.jersey.spi.container.JavaMethodInvokerFactory.invoke(JavaMethodInvokerFactory.java:60)
    at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:205)
    at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
    at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288)
    at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
    at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
    at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1469)
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1400)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339)
    at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
    at com.ibm.ws.cache.servlet.ServletWrapper.serviceProxied(ServletWrapper.java:307)
    at com.ibm.ws.cache.servlet.CacheHook.handleFragment(CacheHook.java:562)
    at com.ibm.ws.cache.servlet.CacheHook.handleServlet(CacheHook.java:255)
    at com.ibm.ws.cache.servlet.ServletWrapper.service(ServletWrapper.java:259)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1232)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:781)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:480)
    at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)
    at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1114)
    at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3928)
    at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:304)
    at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:1007)
    at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1817)
    at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:200)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:463)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:530)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:316)
    at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:88)
    at com.ibm.ws.ssl.channel.impl.SSLReadServiceContext$SSLReadCompletedCallback.complete(SSLReadServiceContext.java:1820)
    at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:175)
    at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
    at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
    at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
    at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
    at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
    at com.ibm.io.async.ResultHandler.run(ResultHandler.java:905)
    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1881)
Caused by: org.hibernate.QueryTimeoutException: Could not open connection
    at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:156)
    at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
    at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:304)
    at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.getConnection(LogicalConnectionImpl.java:169)
    at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doBegin(JdbcTransaction.java:67)
    at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.begin(AbstractTransactionImpl.java:160)
    at org.hibernate.internal.SessionImpl.beginTransaction(SessionImpl.java:1309)
    at org.hibernate.ejb.TransactionImpl.begin(TransactionImpl.java:57)
    ... 48 more
Caused by: java.sql.SQLException: ORA-01017: invalid username/password; logon denied
 DSRA0010E: SQL State = 72000, Error Code = 1,017
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:450)
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:392)
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:385)
    at oracle.jdbc.driver.T4CTTIfun.processError(T4CTTIfun.java:1018)
    at oracle.jdbc.driver.T4CTTIoauthenticate.processError(T4CTTIoauthenticate.java:497)
    at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:522)
    at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:257)
    at oracle.jdbc.driver.T4CTTIoauthenticate.doOAUTH(T4CTTIoauthenticate.java:433)
    at oracle.jdbc.driver.T4CTTIoauthenticate.doOAUTH(T4CTTIoauthenticate.java:950)
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:639)
    at oracle.jdbc.driver.PhysicalConnection.connect(PhysicalConnection.java:662)
    at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
    at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:560)
    at oracle.jdbc.pool.OracleDataSource.getPhysicalConnection(OracleDataSource.java:311)
    at oracle.jdbc.xa.client.OracleXADataSource.getPooledConnection(OracleXADataSource.java:486)
    at oracle.jdbc.xa.client.OracleXADataSource.getXAConnection(OracleXADataSource.java:174)
    at oracle.jdbc.xa.client.OracleXADataSource.getXAConnection(OracleXADataSource.java:109)
    at com.ibm.ws.rsadapter.spi.InternalGenericDataStoreHelper.run(InternalGenericDataStoreHelper.java:1365)
    at com.ibm.ws.security.util.AccessController.doPrivileged(AccessController.java:118)
    at com.ibm.ws.rsadapter.spi.InternalGenericDataStoreHelper.getPooledConnection(InternalGenericDataStoreHelper.java:1384)
    at com.ibm.ws.rsadapter.spi.WSRdbDataSource.getPooledConnection(WSRdbDataSource.java:2154)
    at com.ibm.ws.rsadapter.spi.WSManagedConnectionFactoryImpl.getConnection(WSManagedConnectionFactoryImpl.java:1787)
    at com.ibm.ws.rsadapter.spi.WSManagedConnectionFactoryImpl.createManagedConnection(WSManagedConnectionFactoryImpl.java:1557)
    at com.ibm.ws.rsadapter.spi.WSManagedConnectionFactoryImpl.createManagedConnection(WSManagedConnectionFactoryImpl.java:1113)
    at com.ibm.ejs.j2c.FreePool.createManagedConnectionWithMCWrapper(FreePool.java:2161)
    at com.ibm.ejs.j2c.FreePool.createOrWaitForConnection(FreePool.java:1839)
    at com.ibm.ejs.j2c.PoolManager.reserve(PoolManager.java:3818)
    at com.ibm.ejs.j2c.PoolManager.reserve(PoolManager.java:3094)
    at com.ibm.ejs.j2c.ConnectionManager.allocateMCWrapper(ConnectionManager.java:1548)
    at com.ibm.ejs.j2c.ConnectionManager.allocateConnection(ConnectionManager.java:1031)
    at com.ibm.ws.rsadapter.jdbc.WSJdbcDataSource.getConnection(WSJdbcDataSource.java:644)
    at com.ibm.ws.rsadapter.jdbc.WSJdbcDataSource.getConnection(WSJdbcDataSource.java:611)
    at org.hibernate.service.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:141)
    at org.hibernate.internal.AbstractSessionImpl$NonContextualJdbcConnectionAccess.obtainConnection(AbstractSessionImpl.java:279)
    at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:297)
    ... 53 more

如果您为数据源(或在资源引用绑定中)设置了容器管理的身份验证,但没有为数据源定义组件管理的身份验证,则可能会导致出现此问题,因为您会能够在没有不使用容器管理身份验证的资源引用的情况下查找数据源。要使用容器管理的身份验证,您需要在查找数据源时使用资源引用。

您是否尝试过为持久单元中的数据源指定资源引用名称。例如,

 <jta-data-source>java:comp/env/jdbc/exampleDS</jta-data-source>

参见: http://www.ibm.com/support/knowledgecenter/SSAW57_8.0.0/com.ibm.websphere.nd.doc/info/ae/ae/tejb_defjpadatasource.html

此外,您应该确认您的数据源配置了默认的容器管理的身份验证别名,或者它在资源引用绑定中指定了容器管理的身份验证别名,并且 user/password 是正确的。