I'm trying to connect to my database via a datasource. Currently, it's only working if I provide a user ID and password in the Hibernate config file - but I don't want to do that. Part of the point of using a datasource is to avoid putting user IDs and passwords into config files.... SO, I'm sure I have something configured incorrectly. I just don't know what...
We're running an EAR with four or five basic Java jar files and one WAR file contained in the EAR. (We're in WebSphere - version details below.) The Hibernate jar files are all up in the EAR, and our Persistence project (the jar file with our Java code implementing our Hiberate DAOs) accesses the Hibernate jar files via references from the
MANIFEST.MF in our jar file. I think the code is working. We are able to save objects to and read objects from the database.
Hibernate version: 3.0.5
Database: DB2 version 8.2.2 (for NT)
Application Server: WebSphere 5.1 (testing in Rational Application Developer (RAD) version 6.0.1, using the built-in WebSphere v5.1 Test Environment)
DataSource configuration:
In RAD, in the Admin Console for our WebSphere v5.1 Test Environment, under
Resources, under
JDBC Providers, at the
Server scope, we're using a
DB2 Universal JDBC Driver Provider. We've mapped the driver to its needed jar files (db2jcc.jar and db2jcc_license_cu.jar). The JDBC Driver
Implementation Classname is its default value of
com.ibm.db2.jcc.DB2ConnectionPoolDataSource. We've defined one data source with a JNDI name of
jdbc/EASDataSource. The data source is
not configured for use with
Container managed persistence. The
Datasource Helper Classname has its default value of [coide]com.ibm.websphere.rsadapter.DB2UniversalDataStoreHelper[/i].
Here's what may be the important stuff: The
Component-managed Authentication Alias is left at its default value of
(none). The
Container-managed Authentication Alias is
devEAS_auth_alias, which is a
J2C Authentication Data Entry that defines the name/password I want to be use with the datasource. I believe this is all correct because the "Test Connection" button on the Data Source page works fine.
In the Data Source Custom Properties, we define the database name, we defined the
driverType as 4 so we are using DB2's Type 4 Universal Driver, and we define values for
serverName and
portNumber to define the database connection.
In the code, we're not using any EJBs. Our Hibernate DAOs exist in their own "Persistence" Java jar. So our Hibernate code is not inside any EJB and it's not inside a Servlet - so we're not using the
java:comp/env approach to name the datasource. Instead, the JNDI name of our datasource is simply
jdbc/EASDataSource.
Here's the hibernate.cfg.xml file without the references to our mappings:
Code:
<hibernate-configuration>
<session-factory name="java:comp/env/hibernate/SessionFactory">
<property name="default_schema">EADEV</property>
<property name="connection.datasource">jdbc/EASDataSource</property>
<property name="connection.username">xxx</property>
<property name="connection.password">xxxxxxx</property>
<property name="dialect">org.hibernate.dialect.DB2Dialect</property>
<property name="transaction.factory_class">
org.hibernate.transaction.JTATransactionFactory
</property>
<property name="transaction.manager_lookup_class">
org.hibernate.transaction.WebSphereTransactionManagerLookup
</property>
<property name="jta.UserTransaction">java:comp/UserTransaction</property>
</session-factory>
</hibernate-configuration>
If I leave out the connection username and password, I get this error (see the first error message and then the last line of the stack trace that says "Caused by"):
Code:
[12/8/05 13:38:58:656 CST] 72b7c66b NamingHelper I org.hibernate.util.NamingHelper JNDI InitialContext properties:{}
[12/8/05 13:38:58:922 CST] 72b7c66b DatasourceCon I org.hibernate.connection.DatasourceConnectionProvider Using datasource: jdbc/EASDataSource
[12/8/05 13:38:59:656 CST] 72b7c66b FreePool E J2CA0046E: Method createManagedConnctionWithMCWrapper caught an exception during creation of the ManagedConnection for resource jdbc/EASDataSource, throwing ResourceAllocationException. Original exception: com.ibm.ws.exception.WsException: DSRA8100E: Unable to get a PooledConnection from the DataSource.
at com.ibm.ws.rsadapter.exceptions.DataStoreAdapterException.<init>(DataStoreAdapterException.java:244)
at com.ibm.ws.rsadapter.exceptions.DataStoreAdapterException.<init>(DataStoreAdapterException.java:171)
at com.ibm.ws.rsadapter.AdapterUtil.createDataStoreAdapterException(AdapterUtil.java:209)
at com.ibm.ws.rsadapter.DSConfigurationHelper.getPooledConnection(DSConfigurationHelper.java:911)
at com.ibm.ws.rsadapter.spi.WSRdbDataSource.getPooledConnection(WSRdbDataSource.java:675)
at com.ibm.ws.rsadapter.spi.WSManagedConnectionFactoryImpl.createManagedConnection(WSManagedConnectionFactoryImpl.java:731)
at com.ibm.ejs.j2c.poolmanager.FreePool.createManagedConnectionWithMCWrapper(FreePool.java:1330)
at com.ibm.ejs.j2c.poolmanager.FreePool.createOrWaitForConnection(FreePool.java:1131)
at com.ibm.ejs.j2c.poolmanager.PoolManager.reserve(PoolManager.java:1685)
at com.ibm.ejs.j2c.ConnectionManager.allocateMCWrapper(ConnectionManager.java:685)
at com.ibm.ejs.j2c.ConnectionManager.allocateConnection(ConnectionManager.java:462)
at com.ibm.ws.rsadapter.jdbc.WSJdbcDataSource.getConnection(WSJdbcDataSource.java:241)
at com.ibm.ws.rsadapter.jdbc.WSJdbcDataSource.getConnection(WSJdbcDataSource.java:214)
at org.hibernate.connection.DatasourceConnectionProvider.getConnection(DatasourceConnectionProvider.java:59)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:72)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1463)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1004)
at org.srskansas.eas.persistence.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:24)
at org.srskansas.eas.persistence.hibernate.HibernateCodeTableDAO.save(HibernateCodeTableDAO.java:33)
at org.srskansas.eas.persistence.data.CodeValueFileLoader.main(CodeValueFileLoader.java:89)
at org.srskansas.eas.persistence.data.CoreDataFileLoader.main(CoreDataFileLoader.java:13)
at org.srskansas.eas.common.actions.EASInitializerAction.init(EASInitializerAction.java:31)
at javax.servlet.GenericServlet.init(GenericServlet.java:258)
at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doInit(StrictServletInstance.java:82)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._init(StrictLifecycleServlet.java:147)
at com.ibm.ws.webcontainer.servlet.PreInitializedServletState.init(StrictLifecycleServlet.java:270)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.init(StrictLifecycleServlet.java:113)
at com.ibm.ws.webcontainer.servlet.ServletInstance.init(ServletInstance.java:189)
at javax.servlet.GenericServlet.init(GenericServlet.java:258)
at com.ibm.ws.webcontainer.webapp.WebAppServletManager.addServlet(WebAppServletManager.java:876)
at com.ibm.ws.webcontainer.webapp.WebAppServletManager.loadServlet(WebAppServletManager.java:224)
at com.ibm.ws.webcontainer.webapp.WebAppServletManager.loadAutoLoadServlets(WebAppServletManager.java:542)
at com.ibm.ws.webcontainer.webapp.WebApp.loadServletManager(WebApp.java:1279)
at com.ibm.ws.webcontainer.webapp.WebApp.init(WebApp.java:283)
at com.ibm.ws.webcontainer.srt.WebGroup.loadWebApp(WebGroup.java:392)
at com.ibm.ws.webcontainer.srt.WebGroup.init(WebGroup.java:211)
at com.ibm.ws.webcontainer.WebContainer.addWebApplication(WebContainer.java:1005)
at com.ibm.ws.runtime.component.WebContainerImpl.install(WebContainerImpl.java:136)
at com.ibm.ws.runtime.component.WebContainerImpl.start(WebContainerImpl.java:356)
at com.ibm.ws.runtime.component.ApplicationMgrImpl.start(ApplicationMgrImpl.java:505)
at com.ibm.ws.runtime.component.DeployedApplicationImpl.fireDeployedObjectStart(DeployedApplicationImpl.java:808)
at com.ibm.ws.runtime.component.DeployedModuleImpl.start(DeployedModuleImpl.java:354)
at com.ibm.ws.runtime.component.DeployedApplicationImpl.start(DeployedApplicationImpl.java:578)
at com.ibm.ws.runtime.component.ApplicationMgrImpl.startApplication(ApplicationMgrImpl.java:299)
at com.ibm.ws.runtime.component.ApplicationMgrImpl.startApplication(ApplicationMgrImpl.java:576)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:85)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:58)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java(Compiled Code))
at java.lang.reflect.Method.invoke(Method.java(Compiled Code))
at com.tivoli.jmx.modelmbean.MMBInvoker.invoke(MMBInvoker.java:46)
at com.tivoli.jmx.modelmbean.MMBInvoker.invokeOperation(MMBInvoker.java:115)
at com.tivoli.jmx.modelmbean.DynamicModelMBeanSupport.invoke(DynamicModelMBeanSupport.java:409)
at javax.management.modelmbean.RequiredModelMBean.invoke(RequiredModelMBean.java:323)
at com.tivoli.jmx.GenericMBeanSupport.invoke(GenericMBeanSupport.java:178)
at com.tivoli.jmx.MBeanAccess.invoke(MBeanAccess.java:113)
at com.tivoli.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:290)
at com.ibm.ws.management.AdminServiceImpl.invoke(AdminServiceImpl.java:659)
at com.ibm.ws.management.connector.AdminServiceDelegator.invoke(AdminServiceDelegator.java:130)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:85)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:58)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java(Compiled Code))
at java.lang.reflect.Method.invoke(Method.java(Compiled Code))
at com.ibm.ws.management.connector.soap.SOAPConnector.invoke(SOAPConnector.java:306)
at com.ibm.ws.management.connector.soap.SOAPConnector.service(SOAPConnector.java:176)
at com.ibm.ws.management.connector.soap.SOAPConnection.handleRequest(SOAPConnection.java:55)
at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:615)
at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:439)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:912)
Caused by: com.ibm.db2.jcc.b.SqlException: null userid not supported
If I try an "empty" connection username, I get a different "Caused by" error:
Code:
Caused by: com.ibm.db2.jcc.b.SqlException: userid length, 0, is not allowed.
If I provide
connection.username and
connection.password in
hibernate.cfg.xml, then it all works.
What/how many changes do I need to make to still use my WebSphere managed DataSource to DB2, using the Type 4 driver, without putting a userid and password in the hibernate config file? I want the datasource to always use the name/password defined by WebSphere. I don't want Hibernate to try and provide names/passwords to the datasource. Since the "test connection" button on the datasource page works within the WebSphere Admin Console, I'm confident WebSphere knows the correct name/password to use for this particular datasource. I just haven't been able to figure out why WebSphere is not using that name/password when Hibernate asks for the datasource.
Thanks,
Bill