EJB

Does WebLogic support auto generating primary keys for entity beans?

Yes, this feature was added in WLS 6.1

How should I obtain my JDBC connection so that it participates in the EJB container’s transaction?

You must get your JDBC connection from a TxDataSource or from the JTS driver. If you get a JDBC connections from a plain DataSource or directly from the JDBC driver, it will NOT participate in the EJB container transaction.

TxDataSources are recommended instead of accessing the JTS driver directly. TxDataSources are the standard mechanism in JDBC 2.0 for connection pooling, and they support 2PC/XA transactions.

My transaction aborted, but my database changes did not rollback.

See previous question. You must obtain your JDBC connections from a TxDataSource.

Why did my JDBC code throw a rollback SQLException?

Your JDBC code may throw the following exception:

“The coordinator has rolled back the transaction.

No further JDBC access is allowed within this transaction.”

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

Can I use a join or intermediate table to implement a One-Many relationship?

This is currently not supported. One-Many relationships require that the bean on the Many side of the relationship contain a foreign-key in one of its tables.

When should I use a Stateful session bean and when should I use a servlet session?

The answer to this question is very application-specific and there are situations in which either approach will work. A stateful session bean provides declaritive transaction and security checking as well as failover to a secondary in a cluster.

Why can’t I hold on to a cmr-field (Container Managed Relationship) collection and use it after the transaction commits?

This is prohibited by the EJB 2.0 specification. The reason for disallowing this is that the DBMS data backing a cmr-field collection can change in unpredictable ways once your transaction commits. Tracking these changes is difficult and can result in the contents of the cmr-field collection changing when the application doesn’t expect it. The bottom line is that developers must retrieve and access cmr-field collections within a single transaction.

Can a foreign key column in the database be mapped to both a cmp-field and a cmr-field?

Yes, this has been supported since WLS 6.0 SP1. Note that when the cmp-field is a primary-key field the cmr-field is read-only. In other words, the setXXX method for the cmr-field cannot be used. The value of the primary-key should be initialized as usual in this case.

Conversely, when the cmp-field is not a primary-key field, then the cmp-field is read-only. The underlying column is updated via the cmr-field, and the cmp-field just provides a read-only view of the foreign-key.

Why can’t I call the setXXX method for a cmr-field during ejbCreate?

This is disallowed by the EJB 2.0 specification because the primary-key of the current bean isn’t necessarily known during ejbCreate and it may be needed depending on how the relationship is mapped to the underlying DBMS. Cmr-field setters should be called during ejbPostCreate instead of ejbCreate if relationships need to be setup during creation of a bean.

How can I avoid violating NOT NULL constraints on foreign keys that are mapped to cmr-fields?

In WLS 7.0 and later, you can set delay-database-insert-until to ‘commit’ and assign the cmr-field a value before the current transaction commits. You can also set delay-database-insert-until to ‘ejbPostCreate’ and assign the cmr-field a value during ejbPostCreate.