You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by yu...@live.co.za on 2010/06/14 22:26:02 UTC

hibernate not finding global resource datasource defined by tomcat

Hello tomcats!! 

Please advise as to why hibernate us unable to find jndi datasource configured in tomcat?

Trying 2 different setups here:

1) server.xml resource as follows:

<GlobalNamingResources>
    <!-- Editable user database that can also be used by
         UserDatabaseRealm to authenticate users
    -->
      <Resource
        name="jdbc/auth"
        description="The Jar Bar user authentication"
        type="javax.sql.DataSource"
        auth="Container"
        driverClassName="com.mysql.jdbc.Driver"
        maxActive="30" maxIdle="10"
        maxWait="10000"
        password="myPass"
        url="jdbc:mysql://localhost:3306/yucca123_thejarbar"
        validationQuery="/* ping */ SELECT 1"
        username="yucca123_tom"/>



  </GlobalNamingResources>

throws:
Jun 14, 2010 10:13:20 PM org.apache.catalina.core.ApplicationContext log
Jun 14, 2010 10:13:20 PM org.apache.catalina.core.ApplicationContext log
Jun 14, 2010 10:13:46 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet Faces Servlet threw exception
javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
 at org.apache.naming.NamingContext.lookup(NamingContext.java:770)
 at org.apache.naming.NamingContext.lookup(NamingContext.java:140)
 at org.apache.naming.NamingContext.lookup(NamingContext.java:781)
 at org.apache.naming.NamingContext.lookup(NamingContext.java:140)
 at org.apache.naming.NamingContext.lookup(NamingContext.java:781)
 at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
 at org.apache.naming.SelectorContext.lookup(SelectorContext.java:152)
 at javax.naming.InitialContext.lookup(InitialContext.java:392)
 at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:52)
 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:414)
 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 org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)
 at org.bar.jar.util.HibernateUtil.<clinit>(HibernateUtil.java:24)
 at org.bar.jar.backing.TutorialIndexBacking.getAllUnflaggedComments(TutorialIndexBacking.java:21)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:597)
 at javax.el.BeanELResolver.getValue(BeanELResolver.java:62)
 at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
 at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:72)
 at org.apache.el.parser.AstValue.getValue(AstValue.java:123)
 at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
 at org.apache.jasper.el.JspValueExpression.getValue(JspValueExpression.java:101)
 at javax.faces.component.UIData.getValue(UIData.java:609)
 at javax.faces.component.UIData.getDataModel(UIData.java:1124)
 at javax.faces.component.UIData.setRowIndex(UIData.java:451)
 at com.sun.faces.renderkit.html_basic.TableRenderer.encodeBegin(TableRenderer.java:77)
 at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:813)
 at javax.faces.component.UIData.encodeBegin(UIData.java:962)
 at javax.faces.component.UIComponent.encodeAll(UIComponent.java:928)
 at javax.faces.component.UIComponent.encodeAll(UIComponent.java:933)
 at com.sun.faces.application.ViewHandlerImpl.doRenderView(ViewHandlerImpl.java:266)
 at com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:197)
 at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:110)
 at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
 at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
 at javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
 at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:465)
 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
 at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
 at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
 at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
 at java.lang.Thread.run(Thread.java:619)


with hibernate.cfg.xml:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
  "-//Hibernate/Hibernate Configuration DTD//EN"
  "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
  <session-factory>
    <property name="connection.url">jdbc:mysql://localhost:3306/yucca123_thejarbar</property>
      <property name="hibernate.connection.datasource">java:comp/env/jdbc/auth"</property>
    <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="connection.username">yucca123_tom</property>
      <property name="current_session_context_class">thread</property>
    <property name="connection.password">pookie123</property>
      <mapping resource="org/bar/jar/model/UserRolesEntity.hbm.xml"/>
      <mapping resource="org/bar/jar/model/UsercommentsEntity.hbm.xml"/>
      <mapping resource="org/bar/jar/model/UsersEntity.hbm.xml"/>
      <!-- DB schema will be updated if needed -->
    <!-- <property name="hbm2ddl.auto">update</property> -->
  </session-factory>
</hibernate-configuration>

so I try 

2) moving resource and realm element to context.xml with adding localdatasource attribute to  resource (true) and get same exception?

What am I missing here?

tomcat is latest 6.0.26
mysql 5 with global connector (inside common/lib)

Ideally I want the global(server.xml) config for the resource as it WILL be shared among deployed applications, but because this is first application I am willing to use just contect configured resource.




Re: hibernate not finding global resource datasource defined by tomcat

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Yucca Nel,

On 6/15/2010 1:23 AM, yuccanel@live.co.za wrote:
> --------------------------------------------------
>> From: "Christopher Schultz" <ch...@christopherschultz.net>
>> Subject: Re: hibernate not finding global resource datasource defined by
>> tomcat
>>
>> Maybe you need a <resource-ref> element in your web.xml?
> 
> Can you explain?

No, but you can read.

http://tomcat.apache.org/tomcat-6.0-doc/jndi-resources-howto.html

Search for <resource-ref>.

>> Tomcat 6 doesn't have a common/lib by default. Did you add that?
> 
> No I was merely referring to the fact that I included driver in the lib
> directory of server

Okay, it's confusing to say you put it in common/lib when there's no
common/lib. Precision matters when you're trying to get things working.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkwXsfUACgkQ9CaO5/Lv0PBesACdEKAqcQCTImUYiSmFgD3q2bW7
/ukAniXd3whUB11sa2M26vcO0d+ne3Ot
=SzZZ
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: hibernate not finding global resource datasource defined by tomcat

Posted by yu...@live.co.za.

--------------------------------------------------
From: "Christopher Schultz" <ch...@christopherschultz.net>
Sent: Tuesday, June 15, 2010 12:03 AM
To: "Tomcat Users List" <us...@tomcat.apache.org>
Subject: Re: hibernate not finding global resource datasource defined by 
tomcat

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Yuccal Nel,
>
> On 6/14/2010 4:26 PM, yuccanel@live.co.za wrote:
>> Please advise as to why hibernate us unable to find jndi datasource
>> configured in tomcat?
>
> I'm not sure why Hibernate can't find your JNDI resource, but...
>
>>     <property
>> name="connection.url">jdbc:mysql://localhost:3306/yucca123_thejarbar</property>
>>     <property
>> name="connection.driver_class">com.mysql.jdbc.Driver</property>
>>     <property name="connection.username">yucca123_tom</property>
>>       <property name="current_session_context_class">thread</property>
>>     <property name="connection.password">pookie123</property>
>
> Why do you need these properties in your hibernate configuration? The
> DataSource already knows all these things and you're just confusing
> Hibernate (and yourself) by having them in here. :) No I was just trying 
> to hurry to get working copy up :)
>
>> 2) moving resource and realm element to context.xml with adding
>> localdatasource attribute to  resource (true) and get same exception?
>
> IIRC, localDataSource is a <Realm> option, and has nothing to do with
> the <Resource> or any Hibernate configuration.
>
>> What am I missing here?
>
> Maybe you need a <resource-ref> element in your web.xml?

Can you explain?
>
>> tomcat is latest 6.0.26
>> mysql 5 with global connector (inside common/lib)
>
> Tomcat 6 doesn't have a common/lib by default. Did you add that?

No I was merely referring to the fact that I included driver in the lib 
directory of server
>
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAkwWpyYACgkQ9CaO5/Lv0PDoKwCgoVpt0TcF0EPX8yMhNH2JHivf
> ce8AoK6T283631l+J1hWmxUpFpIyMC8y
> =CZ3Y
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: hibernate not finding global resource datasource defined by tomcat

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Yuccal Nel,

On 6/14/2010 4:26 PM, yuccanel@live.co.za wrote:
> Please advise as to why hibernate us unable to find jndi datasource
> configured in tomcat?

I'm not sure why Hibernate can't find your JNDI resource, but...

>     <property
> name="connection.url">jdbc:mysql://localhost:3306/yucca123_thejarbar</property>
>     <property
> name="connection.driver_class">com.mysql.jdbc.Driver</property>
>     <property name="connection.username">yucca123_tom</property>
>       <property name="current_session_context_class">thread</property>
>     <property name="connection.password">pookie123</property>

Why do you need these properties in your hibernate configuration? The
DataSource already knows all these things and you're just confusing
Hibernate (and yourself) by having them in here.

> 2) moving resource and realm element to context.xml with adding
> localdatasource attribute to  resource (true) and get same exception?

IIRC, localDataSource is a <Realm> option, and has nothing to do with
the <Resource> or any Hibernate configuration.

> What am I missing here?

Maybe you need a <resource-ref> element in your web.xml?

> tomcat is latest 6.0.26
> mysql 5 with global connector (inside common/lib)

Tomcat 6 doesn't have a common/lib by default. Did you add that?

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkwWpyYACgkQ9CaO5/Lv0PDoKwCgoVpt0TcF0EPX8yMhNH2JHivf
ce8AoK6T283631l+J1hWmxUpFpIyMC8y
=CZ3Y
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org