Hi,
I'm trying to connect to a database using a datasource that I provide in the hibernate configuration file. But, I get the following error:
Code:
[2010-08-02 09:54:59,171] [[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)'] ERROR - TYPE=1;SEV=ERROR;ALERTKEY=server.dao.hibernate.PersistFactory:1;SUMMARY=Unable to get Session;CLASS=com.server.dao.hibernate.PersistFactory; -class com.server.dao.hibernate.PersistFactory
org.hibernate.HibernateException: Could not find datasource
at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:56)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56)
at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:410)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:62)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2009)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1292)
at jsp_servlet.__index._jspService(__index.java:97)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:34)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:226)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:124)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:283)
at weblogic.servlet.internal.ServletStubImpl.onAddToMapException(ServletStubImpl.java:394)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:309)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
at org.apache.beehive.netui.pageflow.PageFlowPageFilter.continueChainNoWrapper(PageFlowPageFilter.java:455)
at org.apache.beehive.netui.pageflow.PageFlowPageFilter.runPage(PageFlowPageFilter.java:432)
at org.apache.beehive.netui.pageflow.PageFlowPageFilter.doFilter(PageFlowPageFilter.java:284)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3393)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(Unknown Source)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2140)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2046)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1366)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:200)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:172)
Caused by: javax.naming.NameNotFoundException: While trying to lookup 'jdbc.DFdb2DS' didn't find subcontext 'jdbc'. Resolved ''; remaining name 'jdbc/DFdb2DS'
at weblogic.jndi.internal.BasicNamingNode.newNameNotFoundException(BasicNamingNode.java:1138)
at weblogic.jndi.internal.BasicNamingNode.lookupHere(BasicNamingNode.java:246)
at weblogic.jndi.internal.ServerNamingNode.lookupHere(ServerNamingNode.java:171)
at weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:205)
at weblogic.jndi.internal.WLEventContextImpl.lookup(WLEventContextImpl.java:254)
at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:367)
at javax.naming.InitialContext.lookup(InitialContext.java:351)
at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:52)
... 34 more
Here is my hibernate config file. I tried having the datasource value as "java:/comp/env/jdbc/DFdb2DS". It doesn't work even then.
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="hibernate/SessionFactory">
<property name="connection.datasource">DFdb2DS</property>
<property name="hibernate.dialect">org.hibernate.dialect.DB2Dialect</property>
<property name="show_sql">true</property>
<property name="hibernate.default_schema">DB2TDBA</property>
<property name="transaction.manager_lookup_class">net.sf.hibernate.transaction.WeblogicTransactionManagerLookup</property>
</session-factory>
</hibernate-configuration>
This is the code snippet from the PersistFactory. I get the error when I call the buildSessionFactory() method.
Code:
try {
// Instantiate a new hiberante cofiguration and configure it
Configuration cfg = new Configuration();
cfg.configure(url); //url is the actual path to the hibernate config file
SessionFactory sessionFactory = cfg.buildSessionFactory();
}
catch(Throwable e) {
String message = "Failed to initalize PersistFactory.";
Log.error("2", PersistFactory.class, message, e);
throw new HibernatePersistException(message, e);
}
Does any know what exactly I'm missing here?
Thanks.