openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Benjamin S Vera-Tudela <bveratud...@us.ibm.com>
Subject Questions about OpenJPA issues
Date Thu, 11 Jun 2009 22:06:12 GMT


I am new to JPA and am having a problem with WAS CE 2.1.1.2 (based on
Geronimo) and after two days of researching, I am unable to identify the
issue. Perhaps someone may know what the problem is by the info provided
below. I have included my persistence.xml and deployment plan files in case
someone wants to take a peek at these.

For background, my app is a simple J2EE app with accounts, products, and
promotions among other related objects. After successful deployment on WAS
CE 2.1.1.2, I can access the main JSPs and servlet, but upon posting data
that is used to update the JPA entities via a Stateless Session Bean (SSB)
invoked from the servlet, I get the several instances of the following
message for various entity fields:

672  MyDataAppJPA  WARN   [http-0.0.0.0-8080-1] openjpa.jdbc.Schema -
Existing column "CODE" on table "APP.PROMOTION" is incompatible with the
same column in the given schema definition. Existing column:
Full Name: PROMOTION.CODE
Type: char
Size: 8
Default: null
Not Null: false
Given column:
Full Name: Promotion.code
Type: varchar
Size: 255
Default: null
Not Null: false

These are followed by the exception:

<openjpa-1.2.1-r2180:4612 nonfatal user error>
org.apache.openjpa.persistence.InvalidStateException: You cannot access the
EntityTransaction when using managed transactions.

Any idea what may be causing these errors? Any hints are appreciated.

========================================================================================================================================

For some further background on the app and how the pieces interact, the app
contains:

1) A Web component with a Servlet and JSPs acting as the web front that
interface with the end user
2) An EJB component with a Stateless Session Bean (SSB) used to handle the
transaction boundaries for "complex" business logic using the JPA entitites
3) A JPA component containing all the Entity Beans for my application and
"Entity Managers" generated with RAD (see below for an example)

My servlet instantiates the SSB and Entity Manager as follows:


public class MyDataAppServlet extends HttpServlet {
      private static final long serialVersionUID = 1L;

      @EJB
      private MyDataAppBeanLocal bean;					// Stateless Session Bean reference
      private AccountManager accountMgr = new AccountManager();	// Entity
Manager for the Account JPA entity

      ...
}...


A piece of my SSB code follows:


@Stateless
public class MyDataAppBeanImpl implements MyDataAppBeanLocal {
      static java.util.Random rnd = new java.util.Random
(System.currentTimeMillis());

      @PersistenceContext(unitName="MyDataAppJPA")
      protected EntityManager em;

      @Resource SessionContext ctx;

      public void createAccount(String id, String password, String name,
String type String address1, String address2, String city, String state,
String zipCode)
      throws Exception {
            System.out.println(">>>> Creating account transaction");
            Account account = new Account();
            account.setLoginId(id);
            account.setPassword(password););
            account.setName(name);
            account.setType(type);

            Address address = new Address();
            address.setAddress1(address1););
            address.setAddress2(address2););
            address.setCity(city);
            address.setState(state);
            address.setZipCode(zipCode);););

            account.setAddress(address);););

            em.persist(address);
            em.persist(account);
      }

My servlet may also perform simple updates on JPA entity fields using the
object's "entity manager" (which I actually created using RAD tooling as I
was learning JPA). For instance, from the sample servlet code above, the
accountMgr can be used on an Account JPA entity to persist a simple field
update such as the account's last login timestamp:


      try {
            account.setLastLogin(new Timestamp(System.currentTimeMillis
()));
            accountMgr.updateAccount(account);
      } ....


The AccountManager looks like this (I have commented out annotations
generated from RAD that are tied to WAS and not available in WAS CE such as
@JPAManager and @Action):


//XXX:@JPAManager(targetEntity=com.data.jpa.Account.class)
@SuppressWarnings("unchecked")
public class AccountManager {)

      private EntityManager getEntityManager() {.
            EntityManagerFactory emf = Persistence)
                        .createEntityManagerFactory("MyDataAppJPA");
            return emf.createEntityManager();
      }

      //XXX:@Action(Action.ACTION_TYPE.UPDATE)
      public String updateAccount(Account account) throws Exception {
            EntityManager em = getEntityManager();
            try {
                  em.getTransaction().begin();
                  account = em.merge(account);
                  em.getTransaction().commit();
            } catch (Exception ex) {
                  try {
                        if (em.getTransaction().isActive()) {
                              em.getTransaction().rollback();
                        }
                  } catch (Exception e) {
                        ex.printStackTrace();
                        throw e;
                  }
                  throw ex;
            } finally {
                  em.close();
            }
            return "";);
      }
}}

And finally here is persistence.xml and deployment plan for my JPA and app.

(See attached file: persistence.xml)(See attached file: MyDataApp.xml)



Benjamin S. Vera-Tudela
SWG Middleware Strategy
Ph: (512)-286-9073 T/L 363-9073
E-Mail: bveratudela@us.ibm.com
Mime
  • Unnamed multipart/mixed (inline, None, 0 bytes)
View raw message