4

I am trying to solve this issue from quit sometime now, i am using OSUSER api for simple user and group access. It works fine with JDBC providers(in OsUser.xml and PropertySet.xml)

Now when i am trying to use it with com.opensymphony.user.provider.hibernate.HibernateCredentialsProvider it shows me error:

  at net.sf.hibernate.HibernateException: Could not find datasource: Name jdbc2 is not bound in this Context
  at net.sf.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:47)
  at net.sf.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:75)
  at net.sf.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:144)
  at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:571)
  at com.opensymphony.user.provider.hibernate.dao.SessionManager.<init>(SessionManager.java:34)
  at com.opensymphony.user.provider.hibernate.impl.OSUserHibernateConfigurationProviderImpl.setupConfiguration(OSUserHibernateConfigurationProviderImpl.java:101)
  at com.opensymphony.user.provider.hibernate.HibernateBaseProvider.init(HibernateBaseProvider.java:83)
  at com.opensymphony.user.provider.hibernate.HibernateProfileProvider.init(HibernateProfileProvider.java:98)
  at com.opensymphony.user.util.ConfigLoader.addProvider(ConfigLoader.java:113)
  at com.opensymphony.user.util.ConfigLoader.access$100(ConfigLoader.java:39)
  at com.opensymphony.user.util.ConfigLoader$ConfigHandler.endElement(ConfigLoader.java:144)
  at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:606)
  at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1742)
  at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2900)
  at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:607)
  at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:489)
  at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:835)
  at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
  at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:123)
  at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1210)
  at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:568)
  at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(SAXParserImpl.java:302)
  at javax.xml.parsers.SAXParser.parse(SAXParser.java:195)
  at com.opensymphony.user.util.ConfigLoader.load(ConfigLoader.java:61)
  at com.opensymphony.user.UserManager.<init>(UserManager.java:108)
  at com.opensymphony.user.UserManager.<init>(UserManager.java:60)
  at com.opensymphony.user.UserManager.getInstance(UserManager.java:127)
  at com.fhl.LoginPage$1.onSubmit(LoginPage.java:28)
  at org.apache.wicket.markup.html.form.Form$10.component(Form.java:1157)
  at org.apache.wicket.markup.html.form.Form$10.component(Form.java:1152)
  at org.apache.wicket.util.visit.Visits.visitPostOrderHelper(Visits.java:273)
  at org.apache.wicket.util.visit.Visits.visitPostOrder(Visits.java:244)
  at org.apache.wicket.markup.html.form.Form.delegateSubmit(Form.java:1150)
  at org.apache.wicket.markup.html.form.Form.process(Form.java:803)
  at org.apache.wicket.markup.html.form.Form.onFormSubmitted(Form.java:728)
  at org.apache.wicket.markup.html.form.Form.onFormSubmitted(Form.java:670)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:601)
  at org.apache.wicket.RequestListenerInterface.internalInvoke(RequestListenerInterface.java:260)
  at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:216)
  at org.apache.wicket.request.handler.ListenerInterfaceRequestHandler.invokeListener(ListenerInterfaceRequestHandler.java:179)
  at org.apache.wicket.request.handler.ListenerInterfaceRequestHandler.respond(ListenerInterfaceRequestHandler.java:165)
  at org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:719)
  at org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:63)
  at org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:210)
  at org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:253)
  at org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:162)
  at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:218)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
  at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
  at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
  at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:964)
  at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
  at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:304)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
  at java.lang.Thread.run(Thread.java:722)

Caused by: javax.naming.NameNotFoundException: Name jdbc2 is not bound in this Context
  at org.apache.naming.NamingContext.lookup(NamingContext.java:803)
  at org.apache.naming.NamingContext.lookup(NamingContext.java:159)
  at org.apache.naming.SelectorContext.lookup(SelectorContext.java:158)
  at javax.naming.InitialContext.lookup(InitialContext.java:411)
  at net.sf.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:43)

By the console it seems that it is not able to find the datasource, though i have added hibernate.cfg.xml into the class path and the strange thing is same datasource works fine for JDBC connection.

Here is my hibernate.cfg.xml:

<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="connection.url">jdbc:mysql://localhost/tmpDb2</property>
        <property name="connection.username">root</property>
        <property name="connection.password">fhl</property>

        <!-- Use the C3P0 connection pool. -->
        <property name="c3p0.min_size">3</property>
        <property name="c3p0.max_size">5</property>
        <property name="c3p0.timeout">1800</property>

        <!-- Disable second-level cache. -->
        <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
        <property name="cache.use_query_cache">false</property>
        <property name="cache.use_minimal_puts">false</property>
        <property name="max_fetch_depth">3</property>

        <!-- Print SQL to stdout. -->
        <property name="show_sql">true</property>
        <property name="format_sql">true</property>

        <!-- Drop and then re-create schema on SessionFactory build, for testing. -->
        <property name="hbm2ddl.auto">create</property>

        <!-- Bind the getCurrentSession() method to the thread. -->
        <property name="current_session_context_class">thread</property>

        <!-- Hibernate XML mapping files -->
        <mapping resource="org/MyClass.hbm.xml" />

        <!-- Hibernate Annotations (and package-info.java) <mapping package="org.mypackage"/> 
            <mapping class="org.MyClass/> -->
    </session-factory>
</hibernate-configuration>

Please tell me what am i missing as i am new to hibernate...

Thanks in advance.

3 Answers 3

5

Finally got over with this, Before

    <property name="connection.datasource">fhlabs</property>

After

    <property name="connection.datasource">java:comp/env/fhlabs</property>

works fine now.

0

I think you're missing the datasource configuration for jdbc2.

0

Your setup seem inconsistent. On one hand you are creating a local datasource via hibernate.cfg.xml, yet your stack trace indicates somewhere else your code is hoping a datasource is available via JNDI under the name "jdbc2".

You first need to determine whether to use local / JNDI datasource and setup your environment accordingly

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.