You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Júlio Cesar de Melhado e Lima <jc...@yahoo.com> on 2005/05/30 14:22:26 UTC

Use OJB and JNDI Data Source

Hi all,

I've been using OJB API for a while. Until now, I've used only 
repository_database configurated to access a database directly.
But now I need to configure it to access a database using a JNDI DataSource.
I'm using Tomcat 5.0.28, Postgres 7.4 and OJB 1.0.1.

So, I made available a JNDI Resource "mydatasource", and this resource is 
accessable ( I wrote a tiny jsp page to lookup for this object and 
everything looks fine ).

Then a change the file "repository_database.xml" ( where I keep my database 
configuration ) to :

<jdbc-connection-descriptor
jcd-alias="default"
default-connection="true"
platform="PostgreSQL"
jdbc-level="3.0"
jndi-datasource-name="mydatasource"
batch-mode="false"
useAutoCommit="2"
ignoreAutoCommitExceptions="false">

But when I try to configure OJB to connect to this datasource, I only get an 
exception :

org.apache.ojb.broker.accesslayer.ConnectionFactoryAbstractImpl     -
Naming Exception while looking up DataSource (jdbc/siemens-hpps)
javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
at org.apache.naming.NamingContext.lookup(NamingContext.java:768)
at org.apache.naming.NamingContext.lookup(NamingContext.java:151)
at org.apache.naming.SelectorContext.lookup(SelectorContext.java:136)
at javax.naming.InitialContext.lookup(InitialContext.java:347)
...

Can anyone help with this problem ?

Thanks a lot !
Julio






---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: Use OJB and JNDI Data Source

Posted by Martin Kalén <mk...@apache.org>.
Júlio Cesar de Melhado e Lima wrote:
> I'm using Tomcat 5.0.28, Postgres 7.4 and OJB 1.0.1.
> 
> So, I made available a JNDI Resource "mydatasource", and this resource 
> is accessable ( I wrote a tiny jsp page to lookup for this object and 
> everything looks fine ).
> 
> Then a change the file "repository_database.xml" ( where I keep my 
> database configuration ) to :
> 
> <jdbc-connection-descriptor
> jcd-alias="default"
> default-connection="true"
> platform="PostgreSQL"
> jdbc-level="3.0"
> jndi-datasource-name="mydatasource"
> batch-mode="false"
> useAutoCommit="2"
> ignoreAutoCommitExceptions="false">

You need to specifying the name of the initial JNDI context like so:
  jndi-datasource-name="java:/comp/env/jdbc/mydatasource"

See also Tomcat's JNDI DataSource HOWTO [1] (although the coding
examples will look up the DataSource in the "java:/comp/env" context,
as opposed to OJB's direct lookup in the InitialContext).

If you are later planning on using a managed environment and external
transaction control, set:
  useAutoCommit="0"
and change OJB.properties setting of ConnectionFactoryClass to:
   ConnectionFactoryClass=org.apache.ojb.broker.accesslayer.ConnectionFactoryManagedImpl

Regards,
  Martin

[1] http://jakarta.apache.org/tomcat/tomcat-5.0-doc/jndi-datasource-examples-howto.html

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org