Corporate Info | News | Solutions | Products | Partners | Services | Events | Download | How To Buy
Frequently Asked Questions: Previous topic | Next topic | Contents

WebLogic Frequently Asked Questions: EJB

- SQL Exception and JTS JDBC driver

- Using EJBs with the JDBC-ODBC bridge and Microsoft Access

- Rollback exceptions with EJB applications

- Using a database for EJB bean-managed persistence

- Bugs in Microsoft SDK for Java that affect EJB users

- Exceptions loading EJBs under Microsoft SDK for Java

- Polymorphic responses from create() and find() methods

- EJB transactions and multiple databases

- Container-managed persistence for non-primitive attributes Object-relational mapping tools

- Object-relational mapping tools

- Date datatypes with JDBC container-managed persistence

- Handling exceptions with WebLogic EJB from a Visual Basic client

SQL Exception and JTS JDBC driver

My JDBC code threw the following SQLException:

      "The coordinator has rolled back the transaction.
       No further JDBC access is allowed within this transaction."

What's going on?

The WebLogic JTS JDBC driver throws this exception when the current JDBC Connection transaction rolls back prior to or during the JDBC call. This exception, which is thrown by the WebLogic JTS JDBC driver, means that the transaction in which the JDBC Connection was participating was rolled back at some point prior to or during the JDBC call.

The rollback may have happened in an earlier EJB invoke that was part of the transaction or the rollback may have occurred because the transaction timed out. In either case, the transaction will be rolled back, the connection returned to the pool and the database resources released. In order to proceed, the JTS JDBC Connection must be closed and reopened in a new transaction.

Using EJBs with the JDBC-ODBC bridge and Microsoft Access

I'm having trouble accessing a Microsoft Access database using EJB and the JDBC-ODBC bridge. What's going on?

The Microsoft Access database does not support the type of transaction processing required for use with EJB and the JDBC-ODBC bridge. We recommend that you use another, more robust database such as Microsoft's SQL Server, Informix, Sybase, or Oracle.

Rollback exceptions with EJB applications

When my EJB application produces a rollback exception, the application seems to come to a complete halt. Is there something I can do to optimize how these exceptions are handled?

This problem has been observed when running Windows NT and Oracle and may be due to the way that NT prioritizes threads. The problem is currently under investigation by WebLogic. You may be able to improve performance of your application by decreasing the number of execute threads and increasing the number of connections in the connection pools. For database intensive applications, this is generally a good idea anyway, because the extra threads will waste time waiting for a database connection to become available. Remember that you should set the number of execute threads at least one higher than the number of connections in the connection pool.

Using a database for EJB bean-managed persistence

I am using bean-managed persistence. Does my persistence mechanism need to use the WebLogic JTS driver?

Yes, you must use the WebLogic JTS pool driver for bean-managed EJB persistence. Please see The WebLogic Server EJB Environment for instructions. You must set up a connection pool for use with EJB, and you must access that pool only with the JTS pool driver. WebLogic has successfully tested EJB persistence with both the WebLogic jDriver for Oracle driver and Cloudscape.

Bugs in Microsoft SDK for Java that affect EJB users

Are there any exceptions to using Microsoft SDK for Java with EJBs?

Microsoft SDK for Java serializes objects differently than other JVMs; this causes serialization problems when using EJBs. Therefore, if you want to run WebLogic under Microsoft SDK for Java, you must also use Microsoft SDK for Java when running any EJB utilities, such as the EJB compiler (ejbc).

Exceptions loading EJBs under Microsoft SDK for Java

Why is my WebLogic Server running under Microsoft SDK for Java throwing an exception when it loads my EJBs?

There is an incompatibility in the way in which JavaSoft SDK and Microsoft SDK for Java serialize objects, in this case with javax.ejb.deployment.SerializableField.

You must "create" your EJBs (such as the EJB examples) using jview.exe instead of Sun's java.exe.

Polymorphic responses from create() and find() methods

Why is there no polymorphic-type response from a create() or find() method?

The EJB Specification prohibits this behavior, and the weblogic.ejbc compiler checks for this behavior and prohibits any polymorphic type of response from a create() or find() method.

The reason the create() and find() methods are not polymorphic is much the same reason constructors are not polymorphic in Java. The derived classes generally do not know or cannot initialize the base class properly.

EJB transactions and multiple databases

Can EJB handle transactions across multiple databases?

Currently, the transaction manager in EJB does not have logging, which is a requirement for handling transactions across multiple databases.

Though it might seem possible to accomplish this with multiple entity EJBs handling transactions to each database and a single session EJB to manage a transaction with the entity EJBs, if any one transaction fails, it is not possible to roll the other transactions back.

Container-managed persistence for non-primitive attributes

How do I use container-managed persistence for non-primitive attributes?

First off, the attribute has to be serializable. If it isn't, you can't use it with container-managed persistence.

Let's say you have the three attributes you want to persist:

      public  String          accountId; // also the primary Key
      public  double          balance;
      public  mySerializable  sObj;

The serializableObject can't be mapped directly, but we can map a byte array:

      public  byte[]         ssByteArray;

You will then have four attributes in the EJB. The first three will be mapped to columns in the database:

      public    String                 accountId; // primary Key
      public    double                 balance;
      public    byte[]                 sByteArray;
      transient private mySerializable sObj;

In ejbLoad(), you will convert the byte array sByteArray to the object of type mySerializable.

In ejbStore(), you will do the reverse, updating the byte array so that the container will save it in the database as a BLOB, or "RAW" in Oracle databases:

    public void ejbLoad() throws RemoteException {
      try {
        ByteArrayInputStream ba =
          new ByteArrayInputStream(sByteArray);
        ObjectInputStream p = new ObjectInputStream(ba);
        sObj = (mySerializable) p.readObject();
      } catch (Exception e) {
        throw new RemoteException("Exception in ejbLoad: ", e);
      }
    }

    public void ejbStore() throws RemoteException {
      try {
        ByteArrayOutputStream ba = new ByteArrayOutputStream();
        ObjectOutputStream p = new ObjectOutputStream(ba);
        p.writeObject(sObj);
        sByteArray = ba.toByteArray();
      } catch (Exception e) {
        throw new RemoteException("Exception in ejbLoad: ",e);
      }
    }

Object-relational mapping tools

How does WebLogic make use of an object-relational mapping tool such as JavaBlend with EJB?

Currently, you have to use bean-managed persistence to use tools such as JavaBlend.

Date datatypes with JDBC container-managed persistence

I'm using JDBC container-managed persistence with a Date type field in my database. What data type attribute should I have in my EJB? The Java Date type doesn't work.

Use java.sql.Timestamp instead of Date. See the specific mappings by looking in the appropriate database-specific guide; for example:

- Using WebLogic jDriver for Oracle

Handling exceptions with WebLogic EJB from a Visual Basic client

We are using WebLogic COM from a Visual Basic client to access EJBs that are deployed under WebLogic. If a bean method throws an exception, is it possible to get the exception object, invoke a method on it and then determine if the error generated by Visual Basic is a ValidationException or a RemoteException?

Unfortunately, there are many things you can't do in Visual Basic that you can do in Java. When using Visual Basic, you are limited to looking up RMI and EJB objects and calling methods on those objects. The best way to handle exceptions is to catch them in the EJB and return an error message or code to the Visual Basic client.

Copyright © 2000 BEA Systems, Inc. All rights reserved. Required browser: Netscape 4.0 or higher, or Microsoft Internet Explorer 4.0 or higher.