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 [email protected]
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.
=============================================================