Thanks Jay.

I added setters & getters and now the "deposit()" is working fine. You may bring this up with OpenJPA forum. I will also join and add the comments. Thanks again for help.


On Fri, May 9, 2008 at 2:49 AM, Jay D. McHugh <> wrote:
Hello Phani,

It looks like you are correct about not needing to specify container managed persistence.  It is the default.

After lots of playing with your Account and BankBean classes, it looks like OpenJPA is fine with having your annotations (in on the fields (field access).  But it doesn't seem to be detecting when the fields are directly changed.

So the quick way to get things working is to set up getters and setters on your entity class and use those for altering your entities (basically switch to using property access).

I have never used field access in OpenJPA, so I don't know if you are supposed to need to use setters.

This is probably something that should be brought up on the OpenJPA lists.

Do you want to, or should I?


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

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

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

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
 * 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
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"
          <property name="openjpa.ConnectionDriverName"
value="org.apache.derby.jdbc.EmbeddedDriver" />
          <property name="ConnectionUserName" value="app" />
          <property name="openjpa.jdbc.SynchronizeMappings"


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
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
alias "A
ccount". This could mean that the OpenJPA enhancer or load-time weaver
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