Shared web hosting - CHAPTER 14 Querying with HQL and JPA QL
CHAPTER 14 Querying with HQL and JPA QL from Item as item The as keyword is always optional. The following is equivalent: from Item item Think of this as being a bit like the temporary variable declaration in the following Java code: for ( Iterator i = allQueriedItems.iterator(); i.hasNext(); ) { Item item = (Item) i.next(); … } You assign the alias item to queried instances of the Item class, allowing you to refer to their property values later in the code (or query). To remind yourself of the similarity, we recommend that you use the same naming convention for aliases that you use for temporary variables (camelCase, usually). However, we may use shorter aliases in some of the examples in this book, such as i instead of item, to keep the printed code readable. FAQ Are HQL and JPA QL case sensitive? We never write HQL and JPA QL keywords in uppercase; we never write SQL keywords in uppercase either. It looks ugly and antiquated most modern terminals can display both uppercase and lowercase characters. However, HQL and JPA QL aren t case-sensitive for keywords, so you can write FROM Item AS item if you like shouting. Polymorphic queries HQL and JPA QL, as object-oriented query languages, support polymorphic queries queries for instances of a class and all instances of its subclasses, respectively. You already know enough HQL and JPA QL to be able to demonstrate this. Consider the following query: from BillingDetails This returns objects of the type BillingDetails, which is an abstract class. In this case, the concrete objects are of the subtypes of BillingDetails: CreditCard and BankAccount. If you want only instances of a particular subclass, you may use from CreditCard The class named in the from clause doesn t even need to be a mapped persistent class; any class will do! The following query returns all persistent objects: from java.lang.Object
In case you need quality webspace to host and run your web applications, try our personal web hosting services.