After the step (4), please insert a row in the account table as follows.

"insert into account values (1, 'Owner Name1', 500, 1);"

Phani B madgula

On Thu, May 8, 2008 at 10:14 AM, Phani Madgula <> wrote:
Hi Jay,
I have not explicitly declared transaction configuration. So, the server should run the the method with "TxRequired". The same info has been logged to geronimo.log.

I am attaching the apps 1) EJB app 2) WEB app to test ejb app. You may have a look at the apps. The following are the steps to recreate the problem.

1. Create BankDB database in the embedded derby db server using DB manager portlet.
2. Create Account table using "create table account (accountnumber integer, ownername varchar(50), balance integer, version integer)"
3. Deploy the EJB app
4. Deploy the WEB app
5. Hit the URL in browser window -->http://localhost:8080/AccountCreateWEB/Test?accNo=1

We could see that servlet is calling deposit(accountnumber ,100) method but the value is not being updated in the database.


On Wed, May 7, 2008 at 2:56 PM, Jay D. McHugh <> wrote:

Are you specifying that you want to use container managed persistence in your BankBean?

The way to do this with an annotation would be:

If you are specifying container managed persistence then you wouldn't need to worry about starting and committing your transaction - and the code for your 'deposit' method would work.  Actually, you don't even need the 'manager.merge(account)'.

But, if you are not specifying container managed persistence - then you need to get a UserTransaction and begin/commit it to have your account balance change in your database.

Hope that helps,


Phani Madgula wrote:

I got past the above error but experiencing some strange results as follows.

In the, I have the following method.

  public void deposit(int accountNumber, int amount) {
           Account account = manager.find(Account.class, accountNumber);
           account.balance += amount;
           System.out.println("New balance="+account.balance);
           System.out.println("Merging the account");

I have the as follows.
package sample.jpa;


import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQuery;
import javax.persistence.PostLoad;
import javax.persistence.PostUpdate;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import javax.persistence.Version;
import javax.persistence.Table;

 * This demo entity represents a Bank Account.
 * <p>
 * The entity is not a remote object and can only be accessed locally by
 * clients. However, it is made serializable so that instances can be passed
 * value to remote clients for local inspection.
 * <p>
 * Access to persistent state is by direct field access.
@Table(name = "ACCOUNT")
@NamedQuery(name="findThem", query="SELECT a FROM Account a")
public class Account implements Serializable {

   /** The account number is the primary key for the persistent object */
   public int accountNumber;

   public String ownerName;

   public int balance;

   public int version;

    * Entity beans must have a public no-arg constructor
   public Account() {
       // our own primary key generation, workaround for the
       // time being as persistence does not support
       // auto-generation
       accountNumber = (int) System.nanoTime();

   public String toString() {
       return "Acc.# " + accountNumber + ", owner" + ownerName + ",
balance: " + balance
               + " $";

   void prepersist() {
       System.out.println("pre persist!!");

   void preupdate() {
       System.out.println("pre update!!");

   void postupdate() {
       System.out.println("post update!!");

   void postload() {
       System.out.println("post load!!");


In the servlet I have the following code


 bank = (Bank)ctx.lookup("BankBeanRemote");
 account =

              out.println("account Number =
              out.println("ownerName = "+account.ownerName+"<br/>");
              out.println("balance = "+account.balance+"<br/>");
              out.println("version = "+account.version+"<br/>");

               accountNumber = account.accountNumber;

               out.println("Depositing Rs.100"+"<br/>");



When I run the servlet, it is able to load the account values from the
"account =
statement. However, the "bank.deposit(accountNumber,100);" is not updating
the "balance" field.

What is the problem?? I have the following persistence.xml file
<?xml version="1.0" encoding="UTF-8"?>
<persistence    xmlns=""
   <persistence-unit name="BankPU">
       <description>Bank example</description>

           <property name="openjpa.ConnectionURL" value="jdbc:derby:BankDB"
           <property name="openjpa.ConnectionDriverName"
value="org.apache.derby.jdbc.EmbeddedDriver" />
           <property name="ConnectionUserName" value="app" />
           <property name="openjpa.jdbc.SynchronizeMappings" value="false"


On Wed, May 7, 2008 at 10:52 AM, Phani Madgula <> wrote:


I have an EJB application using JPA and a web application looking up ejbs
in EJB application. I am able to deploy both the applications on AG2.1
server. But when I hit the servlet, I get the following error in the
Message: The bean encountered a non-application exception.; nested
exception is:

       <openjpa-1.0.1-r420667:592145 fatal user error>
stence.ArgumentException: Could not locate metadata for the class using
alias "A
ccount". This could mean that the OpenJPA enhancer or load-time weaver was
not r
un on the type whose alias is "Account". Registered alias mappings:

The ejb app is attached to mail. Any suggestions on what is missing here??