Re: JPA problem in performing DML operations

2008-05-28 Thread Phani Madgula
Hi Jay,

Yes..Understood the missing part. I incorporated transactions using
EntityTransaction. Now the app is working fine.

Thanks for help
Phani


On Thu, May 29, 2008 at 1:20 AM, Jay D. McHugh <[EMAIL PROTECTED]> wrote:

> Phani,
>
> I believe that since you are managing the entity manager, you also need to
> begin and commit your own transactions.
>
> Jay
>
> Phani Madgula wrote:
>
>> 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  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  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 
>> *
>> 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
>>
>> ___
>> 
>> 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";>
>>
>>  
>>
>>  JPA Application Client
>>
>>
>> org.apache.openjpa.persistence.PersistenceProviderImpl
>>  sample.jpa.appclient.Account
>>
>> 
>> > value="jdbc:derby://localhost/AccountDB" />
>> >  name="openjpa.ConnectionDriverName"
>> value="org.apache.derby.jdbc.ClientDriver" />
>> 
>> 
>>
>> 
>>  
>>
>>  
>> 
>> ___
>>
>>
>> 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
>> ___

Re: JPA problem in performing DML operations

2008-05-28 Thread Jay D. McHugh

Phani,

I believe that since you are managing the entity manager, you also need 
to begin and commit your own transactions.


Jay

Phani Madgula wrote:

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

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

  

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