Dean.DePue
Dean.DePue

Reputation: 1013

What do values in persistence.xml mean in EJB?

I am new to Java and JBoss and JDeveloper. My legacy project has this persistence.xml file:

   <persistence-unit name="DoDSRMGR">
    <jta-data-source>java:/DoDSRDS</jta-data-source>
    <class>dodsr.ManifestsPass1</class>
    <class>dodsr.model.ManifestsPass2</class>
       <properties>
         <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
         <property name="javax.persistence.jtaDataSource" value="java:/DoDSRDS"/>
        </properties>
       </persistence-unit>
   </persistence>

My questions are what do the values in the file mean and what are they for? Also, where does this file belong in the EAR file META-INF or the JAR file META-INF? What is the significance of the name="DoDSRMGR" designation, is this the name of the bean when I call from a Java program or is it the application name? Also what is the "java:/DoDSRDS" do?

Is this the way to call the bean from a desktop application: ( DodsrUserSessionEJB) ctx.lookup("/dodsr/"+ejbName+"/remote");

Upvotes: 0

Views: 123

Answers (1)

Roberto Linares
Roberto Linares

Reputation: 2225

<persistence-unit name="DoDSRMGR"> This line lets you put a name to a persistence unit. You use the persistent unit name when you want to instantiate an EntityManager in this way:

EntityManager eMgr = Persistence.createEntityManagerFactory("Your persistence unit name").createEntityManager();

An EntityManager is the object that helps you select, persist, update and remove your JPA entities from/into the database.

<jta-data-source>java:/DoDSRDS</jta-data-source> This line tells you how you are going to manage the persistence transactions (persist, update and remove entities). If you don't specify this line, every time you want to persist, update or remove an entity from the database, you have to first get a transaction instance and call begin() after you persist/update/remove your entity and after that you call the commit() method.

Since you already have the jta-data-source element in your XML you don't need to manually call the begin() and commit() methods. Your application server manages the transactionality via a transaction resource identified by the value "java:/DoDSRDS"

This XML file can be placed in either META-INF or WEB-INF folder.

Upvotes: 1

Related Questions