Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

1. Start the Eclipse IDE and create a Java project by name ApplicationClientJPA as follows ApplicationClientJPA java project.
Right click on the Project Explorer Window and click on New = > Java Project.

Provide ApplicationClientJPA as the name for the Java Project.

Click on Next and Finish.

Right click on the Project and click on the Properties option which is the last option in the menu.

...

Click on Add External JARs button and browse for geronimo-jpa_3.0_spec-1.1.1.jar file in the geronimo
server repository. This file will be available at{{which should be in <geronimo_home>/repository/org/apache/geronimo/specs/}}
geronimo-jpa_3.0_spec/1.1.1 folder. The JPA annotations used in Account.java and some of the JPA
classes used in AccountClient.java requires this library at compile time. Click jar file is only to compile entity and entity client classes you're about to create. Geronimo provides the jar at runtime.
Select the file and click on the Open button.

This will add the library to the build path. Click on OK.

...

2. Create META-INF folder in the project. Right click on the project and click on New = > Folder

Provide META-INF for the folder name and click on Finish.

...

1.Right click on the project and create a Account java class by name Account.java as follows.

Provide name for the class as Account.java and with a package name as sample.jpa.appclient and click . Click on
Finish.

2. Copy the below contents to the Account.java.

Code Block
JAVA
JAVA
borderStylesolid
titleAccount.java
package sample.jpa.appclient;

import java.io.Serializable;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name="Account1")
public class Account implements Serializable{
	

 private static final long serialVersionUID = 1L;

 @Id
 public int accountNo;
 public String name;
 public String address;
 public int branchCode;
 public double balance;

 public Account(){
  this.accountNo = 0;
  this.name = "DUMMY";
  this.address = "DUMMY";
  this.branchCode = 0;
 }
	
 public int getAccountNo() {
  return accountNo;
 }
 
 public void setAccountNo(int accountNo) {
  this.accountNo = accountNo;
 }
 
 public String getName() {
  return name;
 }
 
 public void setName(String name) {
  this.name = name;
 }
 
 public String getAddress() {
  return address;
 }
 
 public void setAddress(String address) {
  this.address = address;
 }
 
 public int getBranchCode() {
  return branchCode;
 }

 public void setBranchCode(int branchCode) {
  this.branchCode = branchCode;
 }

 public double getBalance() {
  return balance;
 }

 public void setBalance(double balance) {
  this.balance = balance;
 }

}

...

Code Block
XML
XML
borderStylesolid
titlepersistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence	
 xmlns="http://java.sun.com/xml/ns/persistence"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 version="1.0"
 xsi:schemaLocation="http://java.sun.com/xml/ns/persistence 
 http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
  version="1.0" >

  <persistence-unit name="JPA-App-Client">
    <description>JPA Application Client</description>
    <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
    <class>sample.jpa.appclient.Account</class>
    <properties>
      <property name="openjpa.ConnectionURL" value="jdbc:derby://localhost/AccountDB" />
      <property name="openjpa.ConnectionDriverName" value="org.apache.derby.jdbc.ClientDriver" />
      <property name="ConnectionUserName" value="app" />
      <property name="openjpa.jdbc.SynchronizeMappings" value="false" />
    </properties>
  </persistence-unit>
</persistence>

...

Code Block
XML
XML
borderStylesolid
titleapplication-client.xml
<?xml version="1.0" encoding="UTF-8"?>

<application-client 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-client_5.xsd"
  version="5">
  
</application-client>

Since we are using JPA annotations to declare the resources, we do not require any entries in the file.

...

Code Block
XML
XML
borderStylesolid
titlegeronimo-application-client.xml
<?xml version="1.0" encoding="UTF-8"?>

<application-client 
 xmlns="http://geronimo.apache.org/xml/ns/j2ee/application-client-2.0" 
  xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.2"
  xmlns:naming="http://geronimo.apache.org/xml/ns/naming-1.2" 
  xmlns:security="http://geronimo.apache.org/xml/ns/security-2.0"
  xmlns:connector="http://geronimo.apache.org/xml/ns/j2ee/connector-1.2">
 
 <sys:client-environment>
  
  <sys:moduleId>
      <sys:groupId>AccountJPA</sys:groupId>
      <sys:artifactId>AccountJPA-app-client</sys:artifactId>

      <sys:version>3.0</sys:version>
      <sys:type>jar</sys:type>
    </sys:moduleId>
  		
  <sys:dependencies>
      <sys:dependency>
        <sys:groupId>org.apache.geronimo.configs</sys:groupId>
        <sys:artifactId>transaction</sys:artifactId>
        <sys:version>2.1</sys:version>
        <sys:type>car</sys:type>
      </sys:dependency>
    </sys:dependencies>	
  

 </sys:client-environment>
  
 <sys:server-environment>
 
 
  <sys:moduleId>
      <sys:groupId>AccountJPA</sys:groupId>
      <sys:artifactId>AccountJPA-app-client-server</sys:artifactId>
      <sys:version>3.0</sys:version>
      <sys:type>jar</sys:type>
    </sys:moduleId>
  

 </sys:server-environment> 
</application-client>

Deploying the application client

...

In the next screen click Next. In the Jar Manifest Specification wizard, select sample.jpa.appclient.AccountClient using Browse button. This is the class that has public static void main(String[] args) method which is the application entry point.

Click Finish.

2. Deploy the application client as follows.

...