Web servers - CHAPTER 14 Querying with HQL and JPA QL
CHAPTER 14 Querying with HQL and JPA QL logical expressions by comparing properties of objects to other properties or literal values using the built-in comparison operators. FAQ What is ternary logic? A row is included in an SQL resultset if and only if the WHERE clause evaluates to true. In Java, notNullObject==null evaluates to false and null==null evaluates to true. In SQL, NOT_NULL_COLUMN=null and null=null both evaluate to null, not true. Thus, SQL needs a special operator, IS NULL, to test whether a value is null. This ternary logic is a way of handling expressions that may be applied to null column values. Treating null not as a special marker but as a regular value is an SQL extension to the familiar binary logic of the relational model. HQL and JPA QL have to support this ternary logic with ternary operators. Let s walk through the most common comparison operators. Comparison expressions HQL and JPA QL support the same basic comparison operators as SQL. Here are a few examples that should look familiar if you know SQL: from Bid bid where bid.amount between 1 and 10 from Bid bid where bid.amount > 100 from User u where u.email in (’foo@bar’, ‘bar@foo’) Because the underlying database implements ternary logic, testing for null values requires some care. Remember that null = null doesn t evaluate to true in SQL, but to null. All comparisons that use a null operand evaluate to null. (That s why you usually don t see the null literal in queries.) HQL and JPA QL provide an SQL-style IS [NOT] NULL operator: from User u where u.email is null from Item i where i.successfulBid is not null This query returns all users with no email address and items which are sold. The LIKE operator allows wildcard searches, where the wildcard symbols are % and _, as in SQL: from User u where u.firstname like ‘G%’ This expression restricts the result to users with a firstname starting with a capital G. You may also negate the LIKE operator, for example, in a substring match expression: from User u where u.firstname not like ‘%Foo B%’
If you are searching for cheap webhost for your web application, please visit MySQL5 Web Hosting services.