openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kevin Sutter" <kwsut...@gmail.com>
Subject Re: Persistence
Date Fri, 09 Jan 2009 18:52:16 GMT
One other item concerning JNDI...  Even if you use something like Simple
JNDI, you would need to use the global JNDI naming convention (ie.
jdbc/myDataSource) and not the component JNDI naming convention (ie.
java:comp/env/jdbc/myDataSource).  The component level jndi name needs to be
provided by a container environment and not all of them do this extra
processing.  It sounds like you are trying to use standard Java projects, so
I doubt that you should be using the component jdni naming convention.

Kevin

On Fri, Jan 9, 2009 at 12:39 PM, Michael Dick <michael.d.dick@gmail.com>wrote:

> Hi Annette,
>
> Well you could get something like Simple JNDI [1] and use it to create a
> JNDI location for your datasource. It might be overkill though.
>
> The other alternative, which we use for unit tests, is to add the
> connection
> information in persistence.xml via custom properties. For example if you
> wanted to connect to Derby you could do something like this :
>
> Persistence.xml :
>    <persistence-unit name="test"
>                      transaction-type="RESOURCE_LOCAL">
>         . . .
>        <properties>
>            <property name="openjpa.ConnectionDriverName"
>                value="org.apache.derby.jdbc.EmbeddedDriver" />
>            <property name="openjpa.ConnectionURL"
>                value="jdbc:derby:/home/mikedd/db/test-database;create=true"
> />
>        </properties>
>         . . .
>    </persistence-unit>
>
> Hope this helps,
>
> -mike
>
> [1] http://www.osjava.org/simple-jndi/
>
> On Fri, Jan 9, 2009 at 11:10 AM, Scherer, Annette <
> Annette.Scherer@huk-coburg.de> wrote:
>
> > Hello,
> >
> > I want to acces a Database via OpenJPA from a Java Project. How can I
> > manage this?
> >
> > In various examples I found the access took place from within an Entity
> > Bean, where the reference for the database was specified in Deployment
> > Descriptor - References.
> > Here is my example:
> >
> > Deployment Descriptor:
> > <resource-ref id="ResourceRef_1225385643170">
> >        <description>
> >        </description>
> >        <res-ref-name>jdbc/selektionendb</res-ref-name>
> >        <res-type>javax.sql.DataSource</res-type>
> >        <res-auth>Container</res-auth>
> >        <res-sharing-scope>Shareable</res-sharing-scope>
> > </resource-ref>
> >
> > Persistence.xml:
> > <persistence-unit name="Selektionen_DB">
> >
> >
>  <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
> >
>  <jta-data-source>java:comp/env/jdbc/selektionendb</jta-data-source>
> >
> > EntityManagerFactory Creation:
> > private OpenJPAEntityManagerFactory getOpenEmf() {
> >        if (this.openEmf == null) {
> >                EntityManagerFactory emf =
> > Persistence.createEntityManagerFactory("Selektionen_DB");
> >                this.openEmf = OpenJPAPersistence.cast(emf);
> >        }
> >        return this.openEmf;
> > }
> >
> >
> > How can I declare the database JNDI-Reference in a pure java project?
> > If not declared, I of course get a NameNotFoundException:
> > javax.naming.ConfigurationException [Root exception is
> > javax.naming.NameNotFoundException: Name comp/jdbc not found in context
> > "java:".]
> >
> >
> >
> >
> > Thank you for help
> > Annette Scherer
> > Abteilung Informatik
> >
> >
> >
> >
> > HUK-COBURG
> > Bahnhofsplatz
> > 96444 Coburg
> > Telefon  09561 96-1718
> > Telefax  09561 96-3671
> > E-Mail   Annette.Scherer@HUK-COBURG.de
> > Internet www.HUK.de
> > =============================================================
> > HUK-COBURG Haftpflicht-Unterstützungs-Kasse kraftfahrender Beamter
> > Deutschlands a. G. in Coburg
> > Reg.-Gericht Coburg HRB 100; St.-Nr. 9212/101/00021
> > Sitz der Gesellschaft: Bahnhofsplatz, 96444 Coburg
> > Vorsitzender des Aufsichtsrats: Werner Strohmayr.
> > Vorstand: Rolf-Peter Hoenen (Sprecher), Wolfgang Flaßhoff, Stefan
> Gronbach,
> > Klaus-Jürgen Heitmann, Dr. Christian Hofer, Dr. Wolfgang Weiler.
> > =============================================================
> >
> >
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message