# cmp2 : EJB 2.0 Container Managed Persistence

This example shows how to use new features of container managed persistence in EJB 2.0, like Entity Relationships and EJB-QL.

The code of the EJBs used in this example comes from the book "Enterprise JavaBeans(TM)" Third Edition by Richard Monson-Haefel
[O'REILLY edition ISBN 0-596-00226-2]

## Examples Showing One to One Relationships:

- One to One Unidirectional Relationship:
  Customer --> Address

- One to One Bidirectional Relationship:
  Customer <--> CreditCard

- One to Many Unidirectional Relationship:
  Customer --> Phone

Run the tests? |

## Examples Showing Many to One, One to Many, and Many to Many Relationships:

- Many to One Unidirectional Relationship:
  Cruise --> Ship

- One to Many Bidirectional Relationship:
  Cruise <--> Reservation

- Many to Many Bidirectional Relationship:
  Customer <--> Reservation

- Many to Many Unidirectional Relationship:
  Reservation --> Cabin

Run the tests? |

## Examples Showing EJB-QL:

- `SELECT OBJECT(s) FROM JE2_Ship AS s WHERE s.tonnage = ?1`
- `SELECT OBJECT(s) FROM JE2_Ship AS s WHERE s.tonnage BETWEEN ?1 AND ?2`
- `SELECT OBJECT(c) FROM JE2_Customer AS c`
- `SELECT OBJECT(c) FROM JE2_Cruise AS c WHERE c.name = ?1`
- `SELECT OBJECT(c) FROM JE2_Customer AS c
  WHERE c.lastName = ?1 AND c.firstName = ?2`
- `SELECT OBJECT(c) FROM JE2_Customer AS c WHERE c.lastName = 'Smith90'`
- `SELECT OBJECT(c) FROM JE2_Customer AS c
  WHERE c.lastName LIKE ?1 AND c.firstName LIKE ?2`
- `SELECT OBJECT(c) FROM JE2_Customer AS c WHERE c.hasGoodCredit = TRUE`
- `SELECT OBJECT(c) FROM JE2_Customer AS c
  WHERE c.homeAddress.city = ?1 AND c.homeAddress.state = ?2`
- `SELECT OBJECT(c) FROM JE2_Customer AS c
  WHERE c.lastName LIKE ?1 AND c.firstName LIKE ?2 AND c.homeAddress.state = ?3`
- `SELECT OBJECT(c) FROM JE2_Cabin AS c WHERE c.deckLevel = ?1`
- `SELECT OBJECT(c) FROM JE2_Customer AS c
  WHERE c.homeAddress.state IN ('FL','TX','AZ','CA')`
- `SELECT OBJECT(c) FROM JE2_Customer AS c WHERE c.reservations IS EMPTY`
- `SELECT OBJECT(c) FROM JE2_Customer AS cust, Cruise AS cr, IN (cr.reservations) AS res
  WHERE cr = ?1 AND cust MEMBER OF res.customers`
- `SELECT a.zip FROM JE2_Address AS a WHERE a.state = ?1`
- `SELECT OBJECT(c) FROM JE2_Customer AS c WHERE c.homeAddress = ?1`
- .....

Run the tests? |