📄 query_hql.pot
字号:
#: query_hql.xml:643#, no-c-formatmsgid "JDBC-style positional parameters <literal>?</literal>"msgstr ""#. Tag: para#: query_hql.xml:648#, no-c-formatmsgid "named parameters <literal>:name</literal>, <literal>:start_date</literal>, <literal>:x1</literal>"msgstr ""#. Tag: para#: query_hql.xml:653#, no-c-formatmsgid "SQL literals <literal>'foo'</literal>, <literal>69</literal>, <literal>6.66E+2</literal>, <literal>'1970-01-01 10:00:01.0'</literal>"msgstr ""#. Tag: para#: query_hql.xml:659#, no-c-formatmsgid "Java <literal>public static final</literal> constants <literal>eg.Color.TABBY</literal>"msgstr ""#. Tag: para#: query_hql.xml:665#, no-c-formatmsgid "<literal>in</literal> and <literal>between</literal> may be used as follows:"msgstr ""#. Tag: programlisting#: query_hql.xml:669#, no-c-formatmsgid "<![CDATA[from DomesticCat cat where cat.name between 'A' and 'B']]>"msgstr ""#. Tag: programlisting#: query_hql.xml:671#, no-c-formatmsgid "<![CDATA[from DomesticCat cat where cat.name in ( 'Foo', 'Bar', 'Baz' )]]>"msgstr ""#. Tag: para#: query_hql.xml:673#, no-c-formatmsgid "and the negated forms may be written"msgstr ""#. Tag: programlisting#: query_hql.xml:677#, no-c-formatmsgid "<![CDATA[from DomesticCat cat where cat.name not between 'A' and 'B']]>"msgstr ""#. Tag: programlisting#: query_hql.xml:679#, no-c-formatmsgid "<![CDATA[from DomesticCat cat where cat.name not in ( 'Foo', 'Bar', 'Baz' )]]>"msgstr ""#. Tag: para#: query_hql.xml:681#, no-c-formatmsgid "Likewise, <literal>is null</literal> and <literal>is not null</literal> may be used to test for null values."msgstr ""#. Tag: para#: query_hql.xml:686#, no-c-formatmsgid "Booleans may be easily used in expressions by declaring HQL query substitutions in Hibernate configuration:"msgstr ""#. Tag: programlisting#: query_hql.xml:691#, no-c-formatmsgid "<![CDATA[<property name=\"hibernate.query.substitutions\">true 1, false 0</property>]]>"msgstr ""#. Tag: para#: query_hql.xml:693#, no-c-formatmsgid "This will replace the keywords <literal>true</literal> and <literal>false</literal> with the literals <literal>1</literal> and <literal>0</literal> in the translated SQL from this HQL:"msgstr ""#. Tag: programlisting#: query_hql.xml:698#, no-c-formatmsgid "<![CDATA[from Cat cat where cat.alive = true]]>"msgstr ""#. Tag: para#: query_hql.xml:700#, no-c-formatmsgid "You may test the size of a collection with the special property <literal>size</literal>, or the special <literal>size()</literal> function."msgstr ""#. Tag: programlisting#: query_hql.xml:705#, no-c-formatmsgid "<![CDATA[from Cat cat where cat.kittens.size > 0]]>"msgstr ""#. Tag: programlisting#: query_hql.xml:707#, no-c-formatmsgid "<![CDATA[from Cat cat where size(cat.kittens) > 0]]>"msgstr ""#. Tag: para#: query_hql.xml:709#, no-c-formatmsgid "For indexed collections, you may refer to the minimum and maximum indices using <literal>minindex</literal> and <literal>maxindex</literal> functions. Similarly, you may refer to the minimum and maximum elements of a collection of basic type using the <literal>minelement</literal> and <literal>maxelement</literal> functions."msgstr ""#. Tag: programlisting#: query_hql.xml:717#, no-c-formatmsgid "<![CDATA[from Calendar cal where maxelement(cal.holidays) > current_date]]>"msgstr ""#. Tag: programlisting#: query_hql.xml:719#, no-c-formatmsgid "<![CDATA[from Order order where maxindex(order.items) > 100]]>"msgstr ""#. Tag: programlisting#: query_hql.xml:721#, no-c-formatmsgid "<![CDATA[from Order order where minelement(order.items) > 10000]]>"msgstr ""#. Tag: para#: query_hql.xml:723#, no-c-formatmsgid "The SQL functions <literal>any, some, all, exists, in</literal> are supported when passed the element or index set of a collection (<literal>elements</literal> and <literal>indices</literal> functions) or the result of a subquery (see below)."msgstr ""#. Tag: programlisting#: query_hql.xml:729#, no-c-formatmsgid "" "<![CDATA[select mother from Cat as mother, Cat as kit\n" "where kit in elements(foo.kittens)]]>"msgstr ""#. Tag: programlisting#: query_hql.xml:731#, no-c-formatmsgid "" "<![CDATA[select p from NameList list, Person p\n" "where p.name = some elements(list.names)]]>"msgstr ""#. Tag: programlisting#: query_hql.xml:733#, no-c-formatmsgid "<![CDATA[from Cat cat where exists elements(cat.kittens)]]>"msgstr ""#. Tag: programlisting#: query_hql.xml:735#, no-c-formatmsgid "<![CDATA[from Player p where 3 > all elements(p.scores)]]>"msgstr ""#. Tag: programlisting#: query_hql.xml:737#, no-c-formatmsgid "<![CDATA[from Show show where 'fizard' in indices(show.acts)]]>"msgstr ""#. Tag: para#: query_hql.xml:739#, no-c-formatmsgid "Note that these constructs - <literal>size</literal>, <literal>elements</literal>, <literal>indices</literal>, <literal>minindex</literal>, <literal>maxindex</literal>, <literal>minelement</literal>, <literal>maxelement</literal> - may only be used in the where clause in Hibernate3."msgstr ""#. Tag: para#: query_hql.xml:746#, no-c-formatmsgid "Elements of indexed collections (arrays, lists, maps) may be referred to by index (in a where clause only):"msgstr ""#. Tag: programlisting#: query_hql.xml:751#, no-c-formatmsgid "<![CDATA[from Order order where order.items[0].id = 1234]]>"msgstr ""#. Tag: programlisting#: query_hql.xml:753#, no-c-formatmsgid "" "<![CDATA[select person from Person person, Calendar calendar\n" "where calendar.holidays['national day'] = person.birthDay\n" " and person.nationality.calendar = calendar]]>"msgstr ""#. Tag: programlisting#: query_hql.xml:755#, no-c-formatmsgid "" "<![CDATA[select item from Item item, Order order\n" "where order.items[ order.deliveredItemIndices[0] ] = item and order.id = 11]]>"msgstr ""#. Tag: programlisting#: query_hql.xml:757#, no-c-formatmsgid "" "<![CDATA[select item from Item item, Order order\n" "where order.items[ maxindex(order.items) ] = item and order.id = 11]]>"msgstr ""#. Tag: para#: query_hql.xml:759#, no-c-formatmsgid "The expression inside <literal>[]</literal> may even be an arithmetic expression."msgstr ""#. Tag: programlisting#: query_hql.xml:763#, no-c-formatmsgid "" "<![CDATA[select item from Item item, Order order\n" "where order.items[ size(order.items) - 1 ] = item]]>"msgstr ""#. Tag: para#: query_hql.xml:765#, no-c-formatmsgid "HQL also provides the built-in <literal>index()</literal> function, for elements of a one-to-many association or collection of values."msgstr ""#. Tag: programlisting#: query_hql.xml:770#, no-c-formatmsgid "" "<![CDATA[select item, index(item) from Order order\n" " join order.items item\n" "where index(item) < 5]]>"msgstr ""#. Tag: para#: query_hql.xml:772#, no-c-formatmsgid "Scalar SQL functions supported by the underlying database may be used"msgstr ""#. Tag: programlisting#: query_hql.xml:776#, no-c-formatmsgid "<![CDATA[from DomesticCat cat where upper(cat.name) like 'FRI%']]>"msgstr ""#. Tag: para#: query_hql.xml:778#, no-c-formatmsgid "If you are not yet convinced by all this, think how much longer and less readable the following query would be in SQL:"msgstr ""#. Tag: programlisting#: query_hql.xml:783#, no-c-formatmsgid "" "<![CDATA[select cust\n" "from Product prod,\n" " Store store\n" " inner join store.customers cust\n" "where prod.name = 'widget'\n" " and store.location.name in ( 'Melbourne', 'Sydney' )\n" " and prod = all elements(cust.currentOrder.lineItems)]]>"msgstr ""#. Tag: para#: query_hql.xml:785#, no-c-formatmsgid "<emphasis>Hint:</emphasis> something like"msgstr ""#. Tag: programlisting#: query_hql.xml:789#, no-c-formatmsgid "" "<![CDATA[SELECT cust.name, cust.address, cust.phone, cust.id, cust.current_order\n" "FROM customers cust,\n" " stores store,\n" " locations loc,\n" " store_customers sc,\n" " product prod\n" "WHERE prod.name = 'widget'\n" " AND store.loc_id = loc.id\n" " AND loc.name IN ( 'Melbourne', 'Sydney' )\n" " AND sc.store_id = store.id\n" " AND sc.cust_id = cust.id\n" " AND prod.id = ALL(\n" " SELECT item.prod_id\n" " FROM line_items item, orders o\n" " WHERE item.order_id = o.id\n" " AND cust.current_order = o.id\n" " )]]>"msgstr ""#. Tag: title#: query_hql.xml:794#, no-c-formatmsgid "The order by clause"msgstr ""#. Tag: para#: query_hql.xml:796#, no-c-formatmsgid "The list returned by a query may be ordered by any property of a returned class or components:"msgstr ""#. Tag: programlisting#: query_hql.xml:800#, no-c-formatmsgid "" "<![CDATA[from DomesticCat cat\n" "order by cat.name asc, cat.weight desc, cat.birthdate]]>"msgstr ""#. Tag: para#: query_hql.xml:802#, no-c-formatmsgid "The optional <literal>asc</literal> or <literal>desc</literal> indicate ascending or descending order respectively."msgstr ""#. Tag: title#: query_hql.xml:809#, no-c-formatmsgid "The group by clause"msgstr ""#. Tag: para#: query_hql.xml:811#, no-c-formatmsgid "A query that returns aggregate values may be grouped by any property of a returned class or components:"msgstr ""#. Tag: programlisting#: query_hql.xml:815#, no-c-formatmsgid "" "<![CDATA[select cat.color, sum(cat.weight), count(cat)\n" "from Cat cat\n" "group by cat.color]]>"msgstr ""#. Tag: programlisting#: query_hql.xml:817#, no-c-formatmsgid "" "<![CDATA[select foo.id, avg(name), max(name)\n" "from Foo foo join foo.names name\n" "group by foo.id]]>"msgstr ""#. Tag: para#: query_hql.xml:819#, no-c-formatmsgid "A <literal>having</literal> clause is also allowed."msgstr ""#. Tag: programlisting#: query_hql.xml:823#, no-c-formatmsgid "" "<![CDATA[select cat.color, sum(cat.weight), count(cat)\n" "from Cat cat\n" "group by cat.color\n" "having cat.color in (eg.Color.TABBY, eg.Color.BLACK)]]>"msgstr ""#. Tag: para#: query_hql.xml:825#, no-c-formatmsgid "SQL functions and aggregate functions are allowed in the <literal>having</literal> and <literal>order by</literal> clauses, if supported by the underlying database (eg. not in MySQL)."msgstr ""#. Tag: programlisting#: query_hql.xml:831#, no-c-formatmsgid "" "<![CDATA[select cat\n" "from Cat cat\n" " join cat.kittens kitten\n" "group by cat.id, cat.name, cat.other, cat.properties\n" "having avg(kitten.weight) > 100\n" "order by count(kitten) asc, sum(kitten.weight) desc]]>"msgstr ""#. Tag: para#: query_hql.xml:833#, no-c-formatmsgid "Note that neither the <literal>group by</literal> clause nor the <literal>order by</literal> clause may contain arithmetic expressions. Also note that Hibernate currently does not expand a grouped entity, so you can't write <literal>group by cat</literal> if all properties of <literal>cat</literal> are non-aggregated. You have to list all non-aggregated properties explicitly."msgstr ""#. Tag: title#: query_hql.xml:845#, no-c-formatmsgid "Subqueries"msgstr ""#. Tag: para#: query_hql.xml:847#, no-c-formatmsgid "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: programlisting#: query_hql.xml:853#, no-c-formatmsgid "" "<![CDATA[from Cat as fatcat\n" "where fatcat.weight > (\n" " select avg(cat.weight) from DomesticCat cat\n" ")]]>"msgstr ""#. Tag: programlisting#: query_hql.xml:855#, no-c-formatmsgid "" "<![CDATA[from DomesticCat as cat\n" "where cat.name = some (\n" " select name.nickName from Name as name\n" ")]]>"msgstr ""#. Tag: programlisting#: query_hql.xml:857#, no-c-formatmsgid "" "<![CDATA[from Cat as cat\n" "where not exists (\n" " from Cat as mate where mate.mate = cat\n" ")]]>"msgstr ""#. Tag: programlisting#: query_hql.xml:859#, no-c-formatmsgid "" "<![CDATA[from DomesticCat as cat\n" "where cat.name not in (\n" " select name.nickName from Name as name\n" ")]]>"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -