persistence@glassfish.java.net

RE: using jpa on existing databases - errata corridge

From: Eve Pokua <gorgeous65_at_msn.com>
Date: Fri, 11 May 2007 10:36:44 +0100

Hi Alessandro,

If it is one DB you are trying to connect to, then why use more than one
connection pool.
Besides in your ejb entity class(stateful or stateless), you would have a
persistenceContext making
a reference to a particular persistence unit and an entity manager, as
below:

@PersistenceContext(name="STOCKDETAILS-ejbPU")


        EntityManager em;

The STOCKDETAILS-ejbPU is basically the persistence unit name.

The persistence unit will contain details of your data source. You would
have already set this up
as mentioned below in your admin console. And you would have already set up
your connection pool and tested it and also set up your JDBC datasource.
The persistence Unit would look a bit like below:

<?xml version="1.0" encoding="UTF-8"?>
<application version="5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/application_5.xsd">
  <display-name>STOCKINFOR2</display-name>
  <module>
    <web>
      <web-uri>STOCKINFOR2-war.war</web-uri>
      <context-root>/STOCKINFOR2-war</context-root>
    </web>
  </module>
  <module>
    <java>STOCKINFOR2-app-client.jar</java>
  </module>
  <module>
    <ejb>STOCKINFOR2-ejb.jar</ejb>
  </module>
</application>

Can I also ask, which IDE you are using?

Thanks

eve

>From: Alessandro Pedrotti <alessandrop_at_anthesi.it> Reply-To:
>persistence_at_glassfish.dev.java.net
>To: persistence_at_glassfish.dev.java.net
>Subject: using jpa on existing databases - errata corridge
>Date: Fri, 11 May 2007 08:32:55 +0200
>
>The question is this:
>
>I've never used jpa and persistence in my java ee 5 application.
>Now i want to introduce it for some features.
>
>My envirorment is glassfishThe question is this:
>
>I want to write a simple ejb and the relative entity using jpa technology,
>but i have the following problem.
>
>My application uses severals connection pools, one pool per customer.
>Currently the pool to be used is dinamically determined via jndi lookup (at
>runtime).
>
>When a new customer is added, he will have its own database.
>So we create the database and the respective connection pool on the appl
>server at runtime via the asadmin tool. No application ear re-packaging and
>re-deploy is required.
>
>Using jpa persistence unit i must statically define it in the
>persistence.xml.
>
>So running my application on domains that have different connection pools,
>requires that my appication ear to be re-packaged, mapping in the
>persistence.xml all the persistence units (that refer to the customer
>database).
>
>This is not good, because in this way i must package a
>configuration-specific ear for every appl server (or domain).
>
>Is this correct?
>
>Is there an alternative to hot deploy the persistence units (with the
>asadmin or smething like it), that will be looked up later via jndi lookup?
>
>The statically source code definition is not usable in my envirorment.
>
>Tahnks
>
>--
>
>__________________
>
>Alessandro Pedrotti
>
>
>Anthesi s.r.l.
>via M.Misone, 14 - Riva del Garda (ITALY)
>Tel. +39 0464 553300 Fax. +39 0464 559010
>
>Http://www.anthesi.it - www.isiportal.com
>
>
>-----------------------------------------------------------------------
>Nota di riservatezza : Il presente messaggio, corredato dei relativi
>allegati, contiene informazioni da considerarsi strettamente riservate,ed è
>destinato esclusivamente al destinatario sopra indicato, il quale è l'unico
>autorizzato ad usarlo, copiarlo e, sotto la propria responsabilità,
>diffonderlo.Chiunque ricevesse questo messaggio per errore o comunque lo
>leggesse senza esserne legittimato è avvertito che trattenerlo, copiarlo,
>divulgarlo, distribuirlo a persone diverse dal destinatario è severamente
>proibito, ed è pregato di rinviarlo immediatamente al mittente
>distruggendone l'originale. Grazie.
>Confidentiality Notice : This message, together with its annexes, contains
>information to be deemed strictly confidential and is destined only to the
>addressee(s) identified above who only may use, copy and, under his/their
>responsibility, further disseminate it. If anyone received this message by
>mistake or reads it without entitlement is forewarned that keeping,
>copying, disseminating or distributing this message to persons other than
>the addressee(s) is strictly forbidden and is asked to transmit it
>immediately to the sender and to erase the original message received. Thank
>you.

_________________________________________________________________
Play your part in making history - Email Britain!
http://www.emailbritain.co.uk/