Joins, reporting (Web hosting company) queries, and subselects Iterator i =
Joins, reporting queries, and subselects Iterator i = session.createQuery(”from User user, LogRecord log” + ” where user.username = log.username”) .list().iterator (); while ( i.hasNext() ) { Object[] pair = (Object[]) i.next(); User user = (User) pair[0]; LogRecord log = (LogRecord) pair[1]; } You can of course apply a SELECT clause to project only the data you re interested in. You probably won t need to use the theta-style joins often. Note that it s currently not possible in HQL or JPA QL to outer join two tables that don t have a mapped association theta-style joins are inner joins. Finally, it s extremely common to perform queries that compare primary key or foreign key values to either query parameters or other primary or foreign key values. Comparing identifiers If you think about identifier comparison in more object-oriented terms, what you re really doing is comparing object references. HQL and JPA QL support the following: from Item i, User u where i.seller = u and u.username = ’steve’ In this query, i.sellerrefers to the foreign key to the USERtable in the ITEM table (on the SELLER_ID column), and user refers to the primary key of the USER table (on the USER_ID column). This query uses a theta-style join and is equivalent to the much preferred from Item i join i.seller u where u.username = ’steve’ On the other hand, the following theta-style join can t be re-expressed as a FROM clause join: from Item i, Bid b where i.seller = b.bidder In this case, i.seller and b.bidder are both foreign keys of the USER table. Note that this is an important query in the application; you use it to identify people bidding for their own items.
Looking for affordable and reliable webhost to host and run your business application? Then look no more and go to servlet web hosting services.