Return-Path: Delivered-To: apmail-geronimo-user-archive@www.apache.org Received: (qmail 20140 invoked from network); 26 May 2008 09:35:35 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 26 May 2008 09:35:35 -0000 Received: (qmail 44874 invoked by uid 500); 26 May 2008 09:35:33 -0000 Delivered-To: apmail-geronimo-user-archive@geronimo.apache.org Received: (qmail 44853 invoked by uid 500); 26 May 2008 09:35:32 -0000 Mailing-List: contact user-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: user@geronimo.apache.org List-Id: Delivered-To: mailing list user@geronimo.apache.org Received: (qmail 44826 invoked by uid 99); 26 May 2008 09:35:32 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 26 May 2008 02:35:32 -0700 X-ASF-Spam-Status: No, hits=2.0 required=10.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of phanibalaji.madgula@gmail.com designates 209.85.198.231 as permitted sender) Received: from [209.85.198.231] (HELO rv-out-0506.google.com) (209.85.198.231) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 26 May 2008 09:34:39 +0000 Received: by rv-out-0506.google.com with SMTP id f6so1888665rvb.55 for ; Mon, 26 May 2008 02:35:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:mime-version:content-type; bh=TJZ77Rzb98r6dnNfGuMQGkLPENp4F7aheuMZZz3pfZ4=; b=vZyMoxrA9gyW4rwM1w5NtO1GTLjxv6fDKvNj5weCnHZ3A2x104BNlq4WoIqyQyMBdSNKnWfpxAggGQUURCI3Ayk24mXIQrrgKLLemsGKapcYRYjP/kgO3yi+tbvpM47SBzNgNVoxr0lveG0oYJdy1E2rCo9a8YKFIAlsl46cPP8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:mime-version:content-type; b=Y9yLFsuGagFiX/APfskWaCaTv98wzyx76mAouUlH6eORiSFbTRW1w9E11weqI1K8Lrko8XMB1XpWQfgjhUxm7CT80ZiBmw4kfrMyL6YgtPnxhtucd7Xi2XddQm1icEcZPVo5o3jddVCNCvbnYtMrqmr7qPNexQh3tgiiuZ4tbaE= Received: by 10.141.89.13 with SMTP id r13mr2079405rvl.177.1211794499147; Mon, 26 May 2008 02:34:59 -0700 (PDT) Received: by 10.141.128.20 with HTTP; Mon, 26 May 2008 02:34:58 -0700 (PDT) Message-ID: <83e2fc4d0805260234ya5155cbs8b4963a39fbe1732@mail.gmail.com> Date: Mon, 26 May 2008 15:04:58 +0530 From: "Phani Madgula" To: "Geronimo User" , "Geronimo Dev" Subject: JPA problem in performing DML operations MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_18497_29634368.1211794498905" X-Virus-Checked: Checked by ClamAV on apache.org ------=_Part_18497_29634368.1211794498905 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi, I have simple JEE application client that uses JPA to perform DB operations on a database running in the embedded Derby. I tried to attached the app to the mail but failed. The JEE client does not look up anyEJBs. It has Account.java entity and AccountClient.java that performs DB operations on the Entity. The following steps explain how to deploy and run the APP. 1. Create AccountDB database using DBManager portlet on the admin console 2. Create Account table in the AccountDB as follows *create table ACCOUNT (ACCOUNTNO integer, NAME varchar (50), ADDRESS varchar (225), BRANCHCODE integer, BALANCE decimal (15,2));* 3. Deploy the app.jar 4. run the client using following options LISTING ACCOUNTS: j*ava -Djava.endorsed.dirs="C:**\Geronimo-2.1\lib\endorsed" -jar C:\Geronimo-2.1\bin\client.jar AccountJPA/AccountJPA-app**-client/3.0/jar list * CREATING AN ACCOUNT: * java -Djava.endorsed.dirs="C:**\Geronimo-2.1\lib\endorsed" -jar C:\Geronimo-2.1\bin\client.jar AccountJPA/AccountJPA-app**-client/3.0/jar create 2222 Joe NC 10 4000 * UPDATING AN ACCOUNT: * java -Djava.endorsed.dirs="C:**\Geronimo-2.1\lib\endorsed" -jar C:\Geronimo-2.1\bin\client.jar AccountJPA/AccountJPA-app**-client/3.0/jar update 2222 8000* DELETING AN ACCOUNT j*ava -Djava.endorsed.dirs="C:**\Geronimo-2.1\lib\endorsed" -jar C:\Geronimo-2.1\bin\client.jar AccountJPA/AccountJPA-app**-client/3.0/jar delete 2222 * The AccountClient.java has all the info. I am able to successfully deploy the APP and perform "list" operation. The list operation lists all the accounts currently in the database. Where as if I tried to perform "create", or "update" or "delete" operations, the JPA is not inserting or updating or deleting corresponding rows in the table. Neither it's throwing any error on the console. What could be the error?? Thanks in advance for your help. persistence.xml ___________________________________________________________________________ JPA Application Client org.apache.openjpa.persistence.PersistenceProviderImpl sample.jpa.appclient.Account _______________________________________________________________________ ACCOUNT.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{ @Id private int accountNo; private String name; private String address; private int branchCode; private 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; } } _______________________________________________________________________ AccountClient.java ________________________________________________________________________ package sample.jpa.appclient; import java.util.ArrayList; import java.util.List; import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.Persistence; import javax.persistence.PersistenceContext; import javax.persistence.Query; public class AccountClient { private EntityManager em; public AccountClient() { EntityManagerFactory emf = Persistence.createEntityManagerFactory("JPA-App-Client"); if(emf == null) System.out.println("emf is null!!!"); em = emf.createEntityManager(); if(em == null) System.out.println("em is null!!!"); } public static void main(String[] args) { AccountClient client = new AccountClient(); String opt = args[0]; if(opt.equals("create")){ if (args.length != 6){ System.out.println("Enter values for accountNo, name, address, branchCode and balance;"); System.exit(0); } else{ int accNo = Integer.parseInt(args[1]); String name = args[2]; String address = args[3]; int branchCode = Integer.parseInt(args[4]); double balance = Double.parseDouble(args[5]); client.createAccount(accNo,name,address,branchCode,balance); } } else if (opt.equals("list")){ List accList = client.listAccounts(); for(int i = 0; i < accList.size(); i++){ System.out.println("____________________________________________"); Account acc = (Account)accList.get(i); System.out.println(acc.getAccountNo()); System.out.println(acc.getName()); System.out.println(acc.getAddress()); System.out.println(acc.getBranchCode()); System.out.println(acc.getBalance()); System.out.println("____________________________________________"); System.out.println(""); } }else if (opt.equals("update")){ if (args.length != 3){ System.out.println("Enter values for accountNo and new balace value ;"); System.exit(0); } else{ int accNo = Integer.parseInt(args[1]); double newbalance = Double.parseDouble(args[2]); client.updateAccountBalance(accNo,newbalance); } }else if (opt.equals("delete")){ if (args.length != 2){ System.out.println("Enter values for accountNo for delete"); System.exit(0); } else { int accNo = Integer.parseInt(args[1]); client.deleteAccount(accNo); } }else { System.out.println("Unknown option selected...!!"); } } public Account createAccount(int accNo, String name, String address, int branchCode, double balance){ Account acc1 = em.find(Account.class, accNo); if(acc1 != null) throw new IllegalArgumentException("Account already exists: Account Number ("+accNo+")"); Account acc = new Account(); acc.setAccountNo(accNo); acc.setAddress(address); acc.setBalance(balance); acc.setBranchCode(branchCode); acc.setName(name); System.out.println("Persisting account entity (accNo = "+accNo+")"); em.persist(acc); System.out.println("Persisted successfully account entity (accNo = "+accNo+")"); return acc; } public List listAccounts(){ if(em == null) System.out.println("em is null!!!"); Query q = em.createQuery("SELECT a FROM Account a"); List currList = q.getResultList(); return currList; } public Account updateAccountBalance(int accNo, double newBalance){ Account acc = em.find(Account.class, accNo); if(acc == null) throw new IllegalArgumentException("Account not found : Account Number ("+accNo+")"); acc.setBalance(newBalance); em.merge(acc); return acc; } public void deleteAccount(int accNo){ Account acc = em.find(Account.class, accNo); if(acc == null) throw new IllegalArgumentException("Account not found : Account Number ("+accNo+")"); em.remove(acc); } } ____________________________________________________________________________ geronimo-application-client.xml ___________________________________________________________________________ AccountJPA AccountJPA-app-client 3.0 jar org.apache.geronimo.configs transaction 2.1 car AccountJPA AccountJPA-app-client-server 3.0 jar __________________________________________________________________________ Thanks Phani ------=_Part_18497_29634368.1211794498905 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi,

I have simple JEE application client that uses JPA to perform DB
operations on a database running in the embedded Derby. I tried to attached the app to the mail but failed.
The JEE client does not look up anyEJBs. It has Account.java entity and AccountClient.java that performs
DB operations on the Entity.

The following steps explain how to deploy and run the APP.
1. Create AccountDB database using DBManager portlet on the admin console

2. Create Account table in the AccountDB as follows
  create table ACCOUNT (ACCOUNTNO integer, NAME varchar (50),
ADDRESS varchar (225), BRANCHCODE integer, BALANCE decimal (15,2));


3. Deploy the app.jar

4. run the client using following options

LISTING ACCOUNTS:

java -Djava.endorsed.dirs="C:
\Geronimo-2.1\lib\endorsed" -jar
C:\Geronimo-2.1\bin\client.jar
AccountJPA/AccountJPA-app
-client/3.0/jar list

CREATING AN ACCOUNT:

java -Djava.endorsed.dirs="C:\Geronimo-2.1\lib\endorsed" -jar
C:\Geronimo-2.1\bin\client.jar
AccountJPA/AccountJPA-app
-client/3.0/jar create 2222 Joe NC 10 4000

UPDATING AN ACCOUNT:

java -Djava.endorsed.dirs="C:\Geronimo-2.1\lib\endorsed" -jar
C:\Geronimo-2.1\bin\client.jar
AccountJPA/AccountJPA-app
-client/3.0/jar update 2222 8000

DELETING AN ACCOUNT

java -Djava.endorsed.dirs="C:\Geronimo-2.1\lib\endorsed" -jar
C:\Geronimo-2.1\bin\client.jar
AccountJPA/AccountJPA-app
-client/3.0/jar delete 2222

The AccountClient.java has all the info.

I am able to successfully deploy the APP and perform "list" operation.
The list operation lists all the accounts currently in the database.

Where as if I tried to perform "create", or "update" or "delete"
operations, the JPA is not inserting or updating or deleting
corresponding rows in the table. Neither it's throwing any error on
the console.

What could be the error?? Thanks in advance for your help.

persistence.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">

      <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>

      <!--
      <jta-data-source>PhoneBookPool</jta-data-source>
      <non-jta-data-source>PhoneBookPool</non-jta-data-source>
      -->
</persistence>
_______________________________________________________________________


ACCOUNT.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{

      @Id
      private int accountNo;
      private String name;
      private String address;
      private int branchCode;
      private 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;
      }

}
_______________________________________________________________________

AccountClient.java
________________________________________________________________________
package sample.jpa.appclient;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;



public class AccountClient {

      private EntityManager em;

      public AccountClient()
      {
              EntityManagerFactory emf =
Persistence.createEntityManagerFactory("JPA-App-Client");
              if(emf == null) System.out.println("emf is null!!!");
              em = emf.createEntityManager();
              if(em == null) System.out.println("em is null!!!");
      }
      public static void main(String[] args) {
              AccountClient client = new AccountClient();

              String opt = args[0];
              if(opt.equals("create")){
                      if (args.length != 6){
                              System.out.println("Enter values for
accountNo, name, address,
branchCode and balance;");
                              System.exit(0);
                      }
                      else{
                              int accNo = Integer.parseInt(args[1]);
                              String name = args[2];
                              String address = args[3];
                              int branchCode = Integer.parseInt(args[4]);
                              double balance = Double.parseDouble(args[5]);

client.createAccount(accNo,name,address,branchCode,balance);
                      }
              } else if (opt.equals("list")){
                      List accList = client.listAccounts();
                  for(int i = 0; i < accList.size(); i++){

System.out.println("____________________________________________");
                      Account acc = (Account)accList.get(i);
                      System.out.println(acc.getAccountNo());
                      System.out.println(acc.getName());
                      System.out.println(acc.getAddress());
                      System.out.println(acc.getBranchCode());
                      System.out.println(acc.getBalance());

System.out.println("____________________________________________");
                      System.out.println("");
                  }
              }else if (opt.equals("update")){
                      if (args.length != 3){
                              System.out.println("Enter values for
accountNo and new balace value ;");
                              System.exit(0);
                      }
                      else{
                              int accNo = Integer.parseInt(args[1]);
                              double newbalance = Double.parseDouble(args[2]);
                              client.updateAccountBalance(accNo,newbalance);
                      }

              }else if (opt.equals("delete")){
                      if (args.length != 2){
                              System.out.println("Enter values for
accountNo for delete");
                              System.exit(0);
                      }
                      else {
                              int accNo = Integer.parseInt(args[1]);
                              client.deleteAccount(accNo);
                      }
              }else
              {
                      System.out.println("Unknown option selected...!!");
              }


      }

      public Account createAccount(int accNo, String name,
                      String address, int branchCode,
                      double balance){

              Account acc1 = em.find(Account.class, accNo);
              if(acc1 != null) throw new
IllegalArgumentException("Account already
exists: Account Number ("+accNo+")");
              Account acc = new Account();
              acc.setAccountNo(accNo);
              acc.setAddress(address);
              acc.setBalance(balance);
              acc.setBranchCode(branchCode);
              acc.setName(name);
              System.out.println("Persisting account entity (accNo =
"+accNo+")");
              em.persist(acc);
              System.out.println("Persisted successfully account
entity (accNo =
"+accNo+")");
              return acc;

      }

      public List listAccounts(){
              if(em == null) System.out.println("em is null!!!");
              Query q = em.createQuery("SELECT a FROM Account a");
              List currList = q.getResultList();
              return currList;
      }


      public Account updateAccountBalance(int accNo, double newBalance){
              Account acc = em.find(Account.class, accNo);
              if(acc == null) throw new IllegalArgumentException("Account not
found : Account Number ("+accNo+")");
      acc.setBalance(newBalance);
              em.merge(acc);
               return acc;

      }

      public void deleteAccount(int accNo){
              Account acc = em.find(Account.class, accNo);
              if(acc == null) throw new IllegalArgumentException("Account not
found : Account Number ("+accNo+")");
              em.remove(acc);
      }


}
____________________________________________________________________________

geronimo-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>
__________________________________________________________________________

Thanks
Phani
------=_Part_18497_29634368.1211794498905--