|
Hibernate example source code file (query_hql.pot)
This example Hibernate source code file (query_hql.pot) is included in the DevDaily.com
"Java Source Code
Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.
The Hibernate query_hql.pot source code
#
# AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: 0\n"
"POT-Creation-Date: 2010-02-11T05:38:15\n"
"PO-Revision-Date: 2010-02-11T05:38:15\n"
"Last-Translator: Automatically generated\n"
"Language-Team: None\n"
"MIME-Version: 1.0\n"
"Content-Type: application/x-publican; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#. Tag: title
#, no-c-format
msgid "HQL: The Hibernate Query Language"
msgstr ""
#. Tag: para
#, no-c-format
msgid "Hibernate uses a powerful query language (HQL) that is similar in appearance to SQL. Compared with SQL, however, HQL is fully object-oriented and understands notions like inheritance, polymorphism and association."
msgstr ""
#. Tag: title
#, no-c-format
msgid "Case Sensitivity"
msgstr ""
#. Tag: para
#, no-c-format
msgid "With the exception of names of Java classes and properties, queries are case-insensitive. So <literal>SeLeCT is the same as sELEct is the same as SELECT, but org.hibernate.eg.FOO is not org.hibernate.eg.Foo, and foo.barSet is not foo.BARSET."
msgstr ""
#. Tag: para
#, no-c-format
msgid "This manual uses lowercase HQL keywords. Some users find queries with uppercase keywords more readable, but this convention is unsuitable for queries embedded in Java code."
msgstr ""
#. Tag: title
#, no-c-format
msgid "The from clause"
msgstr ""
#. Tag: para
#, no-c-format
msgid "The simplest possible Hibernate query is of the form:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "This returns all instances of the class <literal>eg.Cat. You do not usually need to qualify the class name, since auto-import is the default. For example:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "In order to refer to the <literal>Cat in other parts of the query, you will need to assign an alias. For example:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "This query assigns the alias <literal>cat to Cat instances, so you can use that alias later in the query. The as keyword is optional. You could also write:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "Multiple classes can appear, resulting in a cartesian product or \"cross\" join."
msgstr ""
#. Tag: para
#, no-c-format
msgid "It is good practice to name query aliases using an initial lowercase as this is consistent with Java naming standards for local variables (e.g. <literal>domesticCat)."
msgstr ""
#. Tag: title
#, no-c-format
msgid "Associations and joins"
msgstr ""
#. Tag: para
#, no-c-format
msgid "You can also assign aliases to associated entities or to elements of a collection of values using a <literal>join. For example:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "The supported join types are borrowed from ANSI SQL:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "<literal>inner join"
msgstr ""
#. Tag: para
#, no-c-format
msgid "<literal>left outer join"
msgstr ""
#. Tag: para
#, no-c-format
msgid "<literal>right outer join"
msgstr ""
#. Tag: para
#, no-c-format
msgid "<literal>full join (not usually useful)"
msgstr ""
#. Tag: para
#, no-c-format
msgid "The <literal>inner join, left outer join and right outer join constructs may be abbreviated."
msgstr ""
#. Tag: para
#, no-c-format
msgid "You may supply extra join conditions using the HQL <literal>with keyword."
msgstr ""
#. Tag: para
#, no-c-format
msgid "A \"fetch\" join allows associations or collections of values to be initialized along with their parent objects using a single select. This is particularly useful in the case of a collection. It effectively overrides the outer join and lazy declarations of the mapping file for associations and collections. See <xref linkend=\"performance-fetching\" /> for more information."
msgstr ""
#. Tag: para
#, no-c-format
msgid "A fetch join does not usually need to assign an alias, because the associated objects should not be used in the <literal>where clause (or any other clause). The associated objects are also not returned directly in the query results. Instead, they may be accessed via the parent object. The only reason you might need an alias is if you are recursively join fetching a further collection:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "The <literal>fetch construct cannot be used in queries called using iterate() (though scroll() can be used). Fetch should be used together with setMaxResults() or setFirstResult(), as these operations are based on the result rows which usually contain duplicates for eager collection fetching, hence, the number of rows is not what you would expect. Fetch should also not be used together with impromptu with condition. It is possible to create a cartesian product by join fetching more than one collection in a query, so take care in this case. Join fetching multiple collection roles can produce unexpected results for bag mappings, so user discretion is advised when formulating queries in this case. Finally, note that full join fetch and right join fetch are not meaningful."
msgstr ""
#. Tag: para
#, no-c-format
msgid "If you are using property-level lazy fetching (with bytecode instrumentation), it is possible to force Hibernate to fetch the lazy properties in the first query immediately using <literal>fetch all properties."
msgstr ""
#. Tag: title
#, no-c-format
msgid "Forms of join syntax"
msgstr ""
#. Tag: para
#, no-c-format
msgid "HQL supports two forms of association joining: <literal>implicit and explicit."
msgstr ""
#. Tag: para
#, no-c-format
msgid "The queries shown in the previous section all use the <literal>explicit form, that is, where the join keyword is explicitly used in the from clause. This is the recommended form."
msgstr ""
#. Tag: para
#, no-c-format
msgid "The <literal>implicit form does not use the join keyword. Instead, the associations are \"dereferenced\" using dot-notation. implicit joins can appear in any of the HQL clauses. implicit join result in inner joins in the resulting SQL statement."
msgstr ""
#. Tag: title
#, no-c-format
msgid "Referring to identifier property"
msgstr ""
#. Tag: para
#, no-c-format
msgid "There are 2 ways to refer to an entity's identifier property:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "The special property (lowercase) <literal>id may be used to reference the identifier property of an entity provided that the entity does not define a non-identifier property named id."
msgstr ""
#. Tag: para
#, no-c-format
msgid "If the entity defines a named identifier property, you can use that property name."
msgstr ""
#. Tag: para
#, no-c-format
msgid "References to composite identifier properties follow the same naming rules. If the entity has a non-identifier property named id, the composite identifier property can only be referenced by its defined named. Otherwise, the special <literal>id property can be used to reference the identifier property."
msgstr ""
#. Tag: para
#, no-c-format
msgid "Please note that, starting in version 3.2.2, this has changed significantly. In previous versions, <literal>id always referred to the identifier property regardless of its actual name. A ramification of that decision was that non-identifier properties named id could never be referenced in Hibernate queries."
msgstr ""
#. Tag: title
#, no-c-format
msgid "The select clause"
msgstr ""
#. Tag: para
#, no-c-format
msgid "The <literal>select clause picks which objects and properties to return in the query result set. Consider the following:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "The query will select <literal>mates of other Cats. You can express this query more compactly as:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "Queries can return properties of any value type including properties of component type:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "Queries can return multiple objects and/or properties as an array of type <literal>Object[]:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "Or as a <literal>List:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "Or - assuming that the class <literal>Family has an appropriate constructor - as an actual typesafe Java object:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "You can assign aliases to selected expressions using <literal>as:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "This is most useful when used together with <literal>select new map:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "This query returns a <literal>Map from aliases to selected values."
msgstr ""
#. Tag: title
#, no-c-format
msgid "Aggregate functions"
msgstr ""
#. Tag: para
#, no-c-format
msgid "HQL queries can even return the results of aggregate functions on properties:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "The supported aggregate functions are:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "<literal>avg(...), sum(...), min(...), max(...)"
msgstr ""
#. Tag: para
#, no-c-format
msgid "<literal>count(*)"
msgstr ""
#. Tag: para
#, no-c-format
msgid "<literal>count(...), count(distinct ...), count(all...)"
msgstr ""
#. Tag: para
#, no-c-format
msgid "You can use arithmetic operators, concatenation, and recognized SQL functions in the select clause:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "The <literal>distinct and all keywords can be used and have the same semantics as in SQL."
msgstr ""
#. Tag: title
#, no-c-format
msgid "Polymorphic queries"
msgstr ""
#. Tag: para
#, no-c-format
msgid "A query like:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "returns instances not only of <literal>Cat, but also of subclasses like DomesticCat. Hibernate queries can name any Java class or interface in the from clause. The query will return instances of all persistent classes that extend that class or implement the interface. The following query would return all persistent objects:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "The interface <literal>Named might be implemented by various persistent classes:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "These last two queries will require more than one SQL <literal>SELECT. This means that the order by clause does not correctly order the whole result set. It also means you cannot call these queries using Query.scroll()."
msgstr ""
#. Tag: title
#, no-c-format
msgid "The where clause"
msgstr ""
#. Tag: para
#, no-c-format
msgid "The <literal>where clause allows you to refine the list of instances returned. If no alias exists, you can refer to properties by name:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "If there is an alias, use a qualified property name:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "This returns instances of <literal>Cat named 'Fritz'."
msgstr ""
#. Tag: para
#, no-c-format
msgid "The following query:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "returns all instances of <literal>Foo with an instance of bar with a date property equal to the startDate property of the Foo. Compound path expressions make the where clause extremely powerful. Consider the following:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "This query translates to an SQL query with a table (inner) join. For example:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "would result in a query that would require four table joins in SQL."
msgstr ""
#. Tag: para
#, no-c-format
msgid "The <literal>= operator can be used to compare not only properties, but also instances:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "The special property (lowercase) <literal>id can be used to reference the unique identifier of an object. See for more information."
msgstr ""
#. Tag: para
#, no-c-format
msgid "The second query is efficient and does not require a table join."
msgstr ""
#. Tag: para
#, no-c-format
msgid "Properties of composite identifiers can also be used. Consider the following example where <literal>Person has composite identifiers consisting of country and medicareNumber:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "Once again, the second query does not require a table join."
msgstr ""
#. Tag: para
#, no-c-format
msgid "See <xref linkend=\"queryhql-identifier-property\" /> for more information regarding referencing identifier properties)"
msgstr ""
#. Tag: para
#, no-c-format
msgid "The special property <literal>class accesses the discriminator value of an instance in the case of polymorphic persistence. A Java class name embedded in the where clause will be translated to its discriminator value."
msgstr ""
#. Tag: para
#, no-c-format
msgid "You can also use components or composite user types, or properties of said component types. See <xref linkend=\"queryhql-components\" /> for more information."
msgstr ""
#. Tag: para
#, no-c-format
msgid "An \"any\" type has the special properties <literal>id and class that allows you to express a join in the following way (where AuditLog.item is a property mapped with <any>):"
msgstr ""
#. Tag: para
#, no-c-format
msgid "The <literal>log.item.class and payment.class would refer to the values of completely different database columns in the above query."
msgstr ""
#. Tag: title
#, no-c-format
msgid "Expressions"
msgstr ""
#. Tag: para
#, no-c-format
msgid "Expressions used in the <literal>where clause include the following:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "mathematical operators: <literal>+, -, *, /"
msgstr ""
#. Tag: para
#, no-c-format
msgid "binary comparison operators: <literal>=, >=, <=, <>, !=, like"
msgstr ""
#. Tag: para
#, no-c-format
msgid "logical operations <literal>and, or, not"
msgstr ""
#. Tag: para
#, no-c-format
msgid "Parentheses <literal>( ) that indicates grouping"
msgstr ""
#. Tag: para
#, no-c-format
msgid "<literal>in, not in, between, is null, is not null, is empty, is not empty, member of and not member of"
msgstr ""
#. Tag: para
#, no-c-format
msgid "\"Simple\" case, <literal>case ... when ... then ... else ... end, and \"searched\" case, case when ... then ... else ... end"
msgstr ""
#. Tag: para
#, no-c-format
msgid "string concatenation <literal>...||... or concat(...,...)"
msgstr ""
#. Tag: para
#, no-c-format
msgid "<literal>current_date(), current_time(), and current_timestamp()"
msgstr ""
#. Tag: para
#, no-c-format
msgid "<literal>second(...), minute(...), hour(...), day(...), month(...), and year(...)"
msgstr ""
#. Tag: para
#, no-c-format
msgid "Any function or operator defined by EJB-QL 3.0: <literal>substring(), trim(), lower(), upper(), length(), locate(), abs(), sqrt(), bit_length(), mod()"
msgstr ""
#. Tag: para
#, no-c-format
msgid "<literal>coalesce() and nullif()"
msgstr ""
#. Tag: para
#, no-c-format
msgid "<literal>str() for converting numeric or temporal values to a readable string"
msgstr ""
#. Tag: para
#, no-c-format
msgid "<literal>cast(... as ...), where the second argument is the name of a Hibernate type, and extract(... from ...) if ANSI cast() and extract() is supported by the underlying database"
msgstr ""
#. Tag: para
#, no-c-format
msgid "the HQL <literal>index() function, that applies to aliases of a joined indexed collection"
msgstr ""
#. Tag: para
#, no-c-format
msgid "HQL functions that take collection-valued path expressions: <literal>size(), minelement(), maxelement(), minindex(), maxindex(), along with the special elements() and indices functions that can be quantified using some, all, exists, any, in."
msgstr ""
#. Tag: para
#, no-c-format
msgid "Any database-supported SQL scalar function like <literal>sign(), trunc(), rtrim(), and sin()"
msgstr ""
#. Tag: para
#, no-c-format
msgid "JDBC-style positional parameters <literal>?"
msgstr ""
#. Tag: para
#, no-c-format
msgid "named parameters <literal>:name, :start_date, and :x1"
msgstr ""
#. Tag: para
#, no-c-format
msgid "SQL literals <literal>'foo', 69, 6.66E+2, '1970-01-01 10:00:01.0'"
msgstr ""
#. Tag: para
#, no-c-format
msgid "Java <literal>public static final constants eg.Color.TABBY"
msgstr ""
#. Tag: para
#, no-c-format
msgid "<literal>in and between can be used as follows:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "The negated forms can be written as follows:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "Similarly, <literal>is null and is not null can be used to test for null values."
msgstr ""
#. Tag: para
#, no-c-format
msgid "Booleans can be easily used in expressions by declaring HQL query substitutions in Hibernate configuration:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "This will replace the keywords <literal>true and false with the literals 1 and 0 in the translated SQL from this HQL:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "You can test the size of a collection with the special property <literal>size or the special size() function."
msgstr ""
#. Tag: para
#, no-c-format
msgid "For indexed collections, you can refer to the minimum and maximum indices using <literal>minindex and maxindex functions. Similarly, you can refer to the minimum and maximum elements of a collection of basic type using the minelement and maxelement functions. For example:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "The SQL functions <literal>any, some, all, exists, in are supported when passed the element or index set of a collection (elements and indices functions) or the result of a subquery (see below):"
msgstr ""
#. Tag: para
#, no-c-format
msgid "Note that these constructs - <literal>size, elements, indices, minindex, maxindex, minelement, maxelement - can only be used in the where clause in Hibernate3."
msgstr ""
#. Tag: para
#, no-c-format
msgid "Elements of indexed collections (arrays, lists, and maps) can be referred to by index in a where clause only:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "The expression inside <literal>[] can even be an arithmetic expression:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "HQL also provides the built-in <literal>index() function for elements of a one-to-many association or collection of values."
msgstr ""
#. Tag: para
#, no-c-format
msgid "Scalar SQL functions supported by the underlying database can be used:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "Consider how much longer and less readable the following query would be in SQL:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "<emphasis>Hint: something like"
msgstr ""
#. Tag: title
#, no-c-format
msgid "The order by clause"
msgstr ""
#. Tag: para
#, no-c-format
msgid "The list returned by a query can be ordered by any property of a returned class or components:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "The optional <literal>asc or desc indicate ascending or descending order respectively."
msgstr ""
#. Tag: title
#, no-c-format
msgid "The group by clause"
msgstr ""
#. Tag: para
#, no-c-format
msgid "A query that returns aggregate values can be grouped by any property of a returned class or components:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "A <literal>having clause is also allowed."
msgstr ""
#. Tag: para
#, no-c-format
msgid "SQL functions and aggregate functions are allowed in the <literal>having and order by clauses if they are supported by the underlying database (i.e., not in MySQL)."
msgstr ""
#. Tag: para
#, no-c-format
msgid "Neither the <literal>group by clause nor the order by clause can contain arithmetic expressions. Hibernate also does not currently expand a grouped entity, so you cannot write group by cat if all properties of cat are non-aggregated. You have to list all non-aggregated properties explicitly."
msgstr ""
#. Tag: title
#, no-c-format
msgid "Subqueries"
msgstr ""
#. Tag: para
#, no-c-format
msgid "For databases that support subselects, Hibernate supports subqueries within queries. A subquery must be surrounded by parentheses (often by an SQL aggregate function call). Even correlated subqueries (subqueries that refer to an alias in the outer query) are allowed."
msgstr ""
#. Tag: para
#, no-c-format
msgid "Note that HQL subqueries can occur only in the select or where clauses."
msgstr ""
#. Tag: para
#, no-c-format
msgid "Note that subqueries can also utilize <literal>row value constructor syntax. See for more information."
msgstr ""
#. Tag: title
#, no-c-format
msgid "HQL examples"
msgstr ""
#. Tag: para
#, no-c-format
msgid "Hibernate queries can be quite powerful and complex. In fact, the power of the query language is one of Hibernate's main strengths. The following example queries are similar to queries that have been used on recent projects. Please note that most queries you will write will be much simpler than the following examples."
msgstr ""
#. Tag: para
#, no-c-format
msgid "The following query returns the order id, number of items, the given minimum total value and the total value of the order for all unpaid orders for a particular customer. The results are ordered by total value. In determining the prices, it uses the current catalog. The resulting SQL query, against the <literal>ORDER, ORDER_LINE, PRODUCT, CATALOG and PRICE tables has four inner joins and an (uncorrelated) subselect."
msgstr ""
#. Tag: para
#, no-c-format
msgid "What a monster! Actually, in real life, I'm not very keen on subqueries, so my query was really more like this:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "The next query counts the number of payments in each status, excluding all payments in the <literal>AWAITING_APPROVAL status where the most recent status change was made by the current user. It translates to an SQL query with two inner joins and a correlated subselect against the PAYMENT, PAYMENT_STATUS and PAYMENT_STATUS_CHANGE tables."
msgstr ""
#. Tag: para
#, no-c-format
msgid "If the <literal>statusChanges collection was mapped as a list, instead of a set, the query would have been much simpler to write."
msgstr ""
#. Tag: para
#, no-c-format
msgid "The next query uses the MS SQL Server <literal>isNull() function to return all the accounts and unpaid payments for the organization to which the current user belongs. It translates to an SQL query with three inner joins, an outer join and a subselect against the ACCOUNT, PAYMENT, PAYMENT_STATUS, ACCOUNT_TYPE, ORGANIZATION and ORG_USER tables."
msgstr ""
#. Tag: para
#, no-c-format
msgid "For some databases, we would need to do away with the (correlated) subselect."
msgstr ""
#. Tag: title
#, no-c-format
msgid "Bulk update and delete"
msgstr ""
#. Tag: para
#, no-c-format
msgid "HQL now supports <literal>update, delete and insert ... select ... statements. See for more information."
msgstr ""
#. Tag: title
#, no-c-format
msgid "Tips & Tricks"
msgstr ""
#. Tag: para
#, no-c-format
msgid "You can count the number of query results without returning them:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "To order a result by the size of a collection, use the following query:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "If your database supports subselects, you can place a condition upon selection size in the where clause of your query:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "If your database does not support subselects, use the following query:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "As this solution cannot return a <literal>User with zero messages because of the inner join, the following form is also useful:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "Properties of a JavaBean can be bound to named query parameters:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "Collections are pageable by using the <literal>Query interface with a filter:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "Collection elements can be ordered or grouped using a query filter:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "You can find the size of a collection without initializing it:"
msgstr ""
#. Tag: title
#, no-c-format
msgid "Components"
msgstr ""
#. Tag: para
#, no-c-format
msgid "Components can be used similarly to the simple value types that are used in HQL queries. They can appear in the <literal>select clause as follows:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "where the Person's name property is a component. Components can also be used in the <literal>where clause:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "Components can also be used in the <literal>order by clause:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "Another common use of components is in <link linkend=\"queryhql-tuple\">row value constructors."
msgstr ""
#. Tag: title
#, no-c-format
msgid "Row value constructor syntax"
msgstr ""
#. Tag: para
#, no-c-format
msgid "HQL supports the use of ANSI SQL <literal>row value constructor syntax, sometimes referred to AS tuple syntax, even though the underlying database may not support that notion. Here, we are generally referring to multi-valued comparisons, typically associated with components. Consider an entity Person which defines a name component:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "That is valid syntax although it is a little verbose. You can make this more concise by using <literal>row value constructor syntax:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "It can also be useful to specify this in the <literal>select clause:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "Using <literal>row value constructor syntax can also be beneficial when using subqueries that need to compare against multiple values:"
msgstr ""
#. Tag: para
#, no-c-format
msgid "One thing to consider when deciding if you want to use this syntax, is that the query will be dependent upon the ordering of the component sub-properties in the metadata."
msgstr ""
Other Hibernate examples (source code examples)
Here is a short list of links related to this Hibernate query_hql.pot source code file:
|