EJB QL example

Query query = manager.createQuery(
"SELECT c.firstName, c.lastName FROM Customer AS c");
List results = query.getResultList( );
Iterator it = results.iterator( );
while (it.hasNext( )) {
Object[] result = (Object[])it.next( );
String first = (String)result[0];
String last = (String)result[1];
}

m-1, 1-1 : juz .(dot)

SELECT c.creditCard FROM Customer AS c
SELECT c.address.city FROM Customer AS c
SELECT c.creditCard.creditCompany.address FROM Customer AS c

SELECT new com.titan.domain.Name(c.firstName, c.lastName) FROM Customer c

*-m

SELECT new com.titan.domain.Name(c.firstName, c.lastName) FROM Customer c

Join

collection-valued properties, we use joins rather than property
navigation.

inner join

SELECT r FROM Customer AS c, IN( c.reservations ) r

หรือ

SELECT r FROM Customer AS c, INNER JOIN c.reservations r

อีกตัวอย่าง

SELECT cbn.ship FROM Customer
AS c, IN( c.reservations ) r, IN( r.cabins ) cbn

outer join

SELECT c.firstName, c.lastName, p.number
FROM Customer c <strong>LEFT JOIN</strong> c.phoneNumbers p

This query might return the results

David Ortiz 617-555-0900
David Ortiz 617-555-9999
Trot Nixon 781-555-2323
Bill Burke null

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s