Using CMP and EJB QL
WebLogic's EJB container supports container-managed EJB persistence based on the EJB 2.0 specification. When you deploy a CMP entity bean to WebLogic Server, the EJB container automatically handles updates to the EJB's persistent fields by concurrent transactions, synchronizes its state with the underlying database table(s), and manages its relationships with other EJB instances.
WebLogic provides a number of enhancements to the standard CMP requirements. These can be divided into two basic categories: those that provide additional architectural options and make EJB development more convenient, and those that can be used to tune an EJB's performance. In the first category, WebLogic lets you map container-managed fields to columns spread across multiple tables. During the development and prototyping stages, you can make WebLogic generate the necessary SQL tables for all entity beans and relationships defined in the EJB JAR. WebLogic does this by inspecting the information captured in the bean classes, as well as the abstract persistence schema and column mappings defined in the EJB deployment descriptors. In addition, you can ask WebLogic to validate the database schema expected by the EJB container at runtime.
WebLogic lets you defer certain tasks of the EJB container to the underlying database. For instance, if you've configured a remove operation on an entity bean to propagate to all related EJB instances, you can configure WebLogic so that it relies on the database to cascade the deletes to all related rows. Besides this, you can configure entity EJBs so that they rely on the underlying database to automatically generate a primary key when an entity bean is inserted into the table(s). For instance, you could rely on an Oracle sequence, or perhaps on an SQL server's IDENTITY column with AUTO-INCREMENT to automatically generate primary key values when the entity EJB instance is created. In addition, you can configure how the EJB container synchronizes updates to persistent fields with the underlying database.
In the performance category, WebLogic lets you specify precisely when the data associated with an entity bean is inserted into the database table. This is critical if you need to configure bulk inserts when a transaction is committed, or if a relationship field (also called a CMR field) maps to a foreign key column that doesn't allow null values. You also can optimize the performance of the EJB container by eagerly loading related entity beans when a finder query is executed using caching EJB relationships. Finally, field groups let you determine exactly which subset of fields in an EJB is populated as the result of a finder method call. These enhancements, together with the EJB container's support for optimistic concurrency and EJB caching, enable you to tune CMP entity beans effectively.
EJB QL is a portable SQL-like query language that defines the implementation for query (finder and select) methods associated with entity beans. It operates on the abstract persistence schema that you've defined for entity beans packaged in an EJB JAR. WebLogic supports the standard EJB QL features, but also incorporates some much-needed features. These include the support for the DISTINCT and ORDERBY keywords, aggregate functions, and SQL-like subqueries.
You also can define select methods that return the results of multicolumn queries. In this case, the collection is returned in the form of a java.sql.ResultSet, where the columns correspond to either CMP fields or aggregate functions applied to the CMP fields. Finally, WebLogic lets you dynamically construct and execute EJB QL queries in your application code, without requiring you to update and redeploy the EJB JAR.