⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 query_hql.pot

📁 hibernate-distribution-3.3.1.GA-dist.zip源码
💻 POT
📖 第 1 页 / 共 4 页
字号:
# SOME DESCRIPTIVE TITLE.# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.##, fuzzymsgid ""msgstr """Project-Id-Version: PACKAGE VERSION\n""Report-Msgid-Bugs-To: http://bugs.kde.org\n""POT-Creation-Date: 2008-08-14 15:28+0000\n""PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n""Last-Translator: FULL NAME <EMAIL@ADDRESS>\n""Language-Team: LANGUAGE <kde-i18n-doc@kde.org>\n""MIME-Version: 1.0\n""Content-Type: application/x-xml2pot; charset=UTF-8\n""Content-Transfer-Encoding: 8bit\n"#. Tag: title#: query_hql.xml:29#, no-c-formatmsgid "HQL: The Hibernate Query Language"msgstr ""#. Tag: para#: query_hql.xml:31#, no-c-formatmsgid "Hibernate is equipped with an extremely powerful query language that (quite intentionally) looks very much like SQL. But don't be fooled by the syntax; HQL is fully object-oriented, understanding notions like inheritence, polymorphism and association."msgstr ""#. Tag: title#: query_hql.xml:38#, no-c-formatmsgid "Case Sensitivity"msgstr ""#. Tag: para#: query_hql.xml:40#, no-c-formatmsgid "Queries are case-insensitive, except for names of Java classes and properties. So <literal>SeLeCT</literal> is the same as <literal>sELEct</literal> is the same as <literal>SELECT</literal> but <literal>org.hibernate.eg.FOO</literal> is not <literal>org.hibernate.eg.Foo</literal> and <literal>foo.barSet</literal> is not <literal>foo.BARSET</literal>."msgstr ""#. Tag: para#: query_hql.xml:51#, no-c-formatmsgid "This manual uses lowercase HQL keywords. Some users find queries with uppercase keywords more readable, but we find this convention ugly when embedded in Java code."msgstr ""#. Tag: title#: query_hql.xml:59#, no-c-formatmsgid "The from clause"msgstr ""#. Tag: para#: query_hql.xml:61#, no-c-formatmsgid "The simplest possible Hibernate query is of the form:"msgstr ""#. Tag: programlisting#: query_hql.xml:65#, no-c-formatmsgid "<![CDATA[from eg.Cat]]>"msgstr ""#. Tag: para#: query_hql.xml:67#, no-c-formatmsgid "which simply returns all instances of the class <literal>eg.Cat</literal>. We don't usually need to qualify the class name, since <literal>auto-import</literal> is the default. So we almost always just write:"msgstr ""#. Tag: programlisting#: query_hql.xml:73#, no-c-formatmsgid "<![CDATA[from Cat]]>"msgstr ""#. Tag: para#: query_hql.xml:75#, no-c-formatmsgid "Most of the time, you will need to assign an <emphasis>alias</emphasis>, since you will want to refer to the <literal>Cat</literal> in other parts of the query."msgstr ""#. Tag: programlisting#: query_hql.xml:81 query_hql.xml:396#, no-c-formatmsgid "<![CDATA[from Cat as cat]]>"msgstr ""#. Tag: para#: query_hql.xml:83#, no-c-formatmsgid "This query assigns the alias <literal>cat</literal> to <literal>Cat</literal> instances, so we could use that alias later in the query. The <literal>as</literal> keyword is optional; we could also write:"msgstr ""#. Tag: programlisting#: query_hql.xml:89#, no-c-formatmsgid "<![CDATA[from Cat cat]]>"msgstr ""#. Tag: para#: query_hql.xml:91#, no-c-formatmsgid "Multiple classes may appear, resulting in a cartesian product or \"cross\" join."msgstr ""#. Tag: programlisting#: query_hql.xml:95#, no-c-formatmsgid "<![CDATA[from Formula, Parameter]]>"msgstr ""#. Tag: programlisting#: query_hql.xml:96#, no-c-formatmsgid "<![CDATA[from Formula as form, Parameter as param]]>"msgstr ""#. Tag: para#: query_hql.xml:98#, no-c-formatmsgid "It is considered good practice to name query aliases using an initial lowercase, consistent with Java naming standards for local variables (eg. <literal>domesticCat</literal>)."msgstr ""#. Tag: title#: query_hql.xml:107#, no-c-formatmsgid "Associations and joins"msgstr ""#. Tag: para#: query_hql.xml:109#, no-c-formatmsgid "We may also assign aliases to associated entities, or even to elements of a collection of values, using a <literal>join</literal>."msgstr ""#. Tag: programlisting#: query_hql.xml:114#, no-c-formatmsgid ""      "<![CDATA[from Cat as cat\n"      "    inner join cat.mate as mate\n"      "    left outer join cat.kittens as kitten]]>"msgstr ""#. Tag: programlisting#: query_hql.xml:116#, no-c-formatmsgid "<![CDATA[from Cat as cat left join cat.mate.kittens as kittens]]>"msgstr ""#. Tag: programlisting#: query_hql.xml:118#, no-c-formatmsgid "<![CDATA[from Formula form full join form.parameter param]]>"msgstr ""#. Tag: para#: query_hql.xml:120#, no-c-formatmsgid "The supported join types are borrowed from ANSI SQL"msgstr ""#. Tag: literal#: query_hql.xml:127#, no-c-formatmsgid "inner join"msgstr ""#. Tag: literal#: query_hql.xml:132#, no-c-formatmsgid "left outer join"msgstr ""#. Tag: literal#: query_hql.xml:137#, no-c-formatmsgid "right outer join"msgstr ""#. Tag: para#: query_hql.xml:141#, no-c-formatmsgid "<literal>full join</literal> (not usually useful)"msgstr ""#. Tag: para#: query_hql.xml:147#, no-c-formatmsgid "The <literal>inner join</literal>, <literal>left outer join</literal> and <literal>right outer join</literal> constructs may be abbreviated."msgstr ""#. Tag: programlisting#: query_hql.xml:152#, no-c-formatmsgid ""      "<![CDATA[from Cat as cat\n"      "    join cat.mate as mate\n"      "    left join cat.kittens as kitten]]>"msgstr ""#. Tag: para#: query_hql.xml:154#, no-c-formatmsgid "You may supply extra join conditions using the HQL <literal>with</literal> keyword."msgstr ""#. Tag: programlisting#: query_hql.xml:159#, no-c-formatmsgid ""      "<![CDATA[from Cat as cat\n"      "    left join cat.kittens as kitten\n"      "        with kitten.bodyWeight > 10.0]]>"msgstr ""#. Tag: para#: query_hql.xml:161#, no-c-formatmsgid "In addition, 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: programlisting#: query_hql.xml:169#, no-c-formatmsgid ""      "<![CDATA[from Cat as cat\n"      "    inner join fetch cat.mate\n"      "    left join fetch cat.kittens]]>"msgstr ""#. Tag: para#: query_hql.xml:171#, no-c-formatmsgid "A fetch join does not usually need to assign an alias, because the associated objects should not be used in the <literal>where</literal> clause (or any other clause). Also, the associated objects are not returned directly in the query results. Instead, they may be accessed via the parent object. The only reason we might need an alias is if we are recursively join fetching a further collection:"msgstr ""#. Tag: programlisting#: query_hql.xml:179#, no-c-formatmsgid ""      "<![CDATA[from Cat as cat\n"      "    inner join fetch cat.mate\n"      "    left join fetch cat.kittens child\n"      "    left join fetch child.kittens]]>"msgstr ""#. Tag: para#: query_hql.xml:181#, no-c-formatmsgid "Note that the <literal>fetch</literal> construct may not be used in queries called using <literal>iterate()</literal> (though <literal>scroll()</literal> can be used). Nor should <literal>fetch</literal> be used together with <literal>setMaxResults()</literal> or <literal>setFirstResult()</literal> 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'd expect. Nor may <literal>fetch</literal> be used together with an ad hoc <literal>with</literal> 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 also sometimes gives unexpected results for bag mappings, so be careful about how you formulate your queries in this case. Finally, note that <literal>full join fetch</literal> and <literal>right join fetch</literal> are not meaningful."msgstr ""#. Tag: para#: query_hql.xml:196#, no-c-formatmsgid "If you are using property-level lazy fetching (with bytecode instrumentation), it is possible to force Hibernate to fetch the lazy properties immediately (in the first query) using <literal>fetch all properties</literal>."msgstr ""#. Tag: programlisting#: query_hql.xml:202#, no-c-formatmsgid "<![CDATA[from Document fetch all properties order by name]]>"msgstr ""#. Tag: programlisting#: query_hql.xml:203#, no-c-formatmsgid "<![CDATA[from Document doc fetch all properties where lower(doc.name) like '%cats%']]>"msgstr ""#. Tag: title#: query_hql.xml:208#, no-c-formatmsgid "Forms of join syntax"msgstr ""#. Tag: para#: query_hql.xml:210#, no-c-formatmsgid "HQL supports two forms of association joining: <literal>implicit</literal> and <literal>explicit</literal>."msgstr ""#. Tag: para#: query_hql.xml:214#, no-c-formatmsgid "The queries shown in the previous section all use the <literal>explicit</literal> form where the join keyword is explicitly used in the from clause. This is the recommended form."msgstr ""#. Tag: para#: query_hql.xml:219#, no-c-formatmsgid "The <literal>implicit</literal> form does not use the join keyword. Instead, the associations are \"dereferenced\" using dot-notation. <literal>implicit</literal> joins can appear in any of the HQL clauses. <literal>implicit</literal> join result in inner joins in the resulting SQL statement."msgstr ""#. Tag: programlisting#: query_hql.xml:226#, no-c-formatmsgid "<![CDATA[from Cat as cat where cat.mate.name like '%s%']]>"msgstr ""#. Tag: title#: query_hql.xml:230#, no-c-formatmsgid "Refering to identifier property"msgstr ""#. Tag: para#: query_hql.xml:232#, no-c-formatmsgid "There are, generally speaking, 2 ways to refer to an entity's identifier property:"msgstr ""#. Tag: para#: query_hql.xml:237#, no-c-formatmsgid "The special property (lowercase) <literal>id</literal> may be used to reference the identifier property of an entity <emphasis>provided that entity does not define a non-identifier property named id</emphasis>."msgstr ""#. Tag: para#: query_hql.xml:244#, no-c-formatmsgid "If the entity defines a named identifier property, you may use that property name."msgstr ""#. Tag: para#: query_hql.xml:250#, no-c-formatmsgid "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</literal> property can be used to rerference the identifier property."msgstr ""#. Tag: para#: query_hql.xml:257#, no-c-formatmsgid "Note: this has changed significantly starting in version 3.2.2. In previous versions, <literal>id</literal> <emphasis>always</emphasis> referred to the identifier property no matter what its actual name. A ramification of that decision was that non-identifier properties named <literal>id</literal> could never be referenced in Hibernate queries."msgstr ""#. Tag: title#: query_hql.xml:266#, no-c-formatmsgid "The select clause"msgstr ""#. Tag: para#: query_hql.xml:268#, no-c-formatmsgid "The <literal>select</literal> clause picks which objects and properties to return in the query result set. Consider:"msgstr ""#. Tag: programlisting#: query_hql.xml:273#, no-c-formatmsgid ""      "<![CDATA[select mate\n"      "from Cat as cat\n"      "    inner join cat.mate as mate]]>"msgstr ""#. Tag: para#: query_hql.xml:275#, no-c-formatmsgid "The query will select <literal>mate</literal>s of other <literal>Cat</literal>s. Actually, you may express this query more compactly as:"msgstr ""#. Tag: programlisting#: query_hql.xml:280#, no-c-formatmsgid "<![CDATA[select cat.mate from Cat cat]]>"msgstr ""#. Tag: para#: query_hql.xml:282#, no-c-formatmsgid "Queries may return properties of any value type including properties of component type:"msgstr ""#. Tag: programlisting#: query_hql.xml:286#, no-c-formatmsgid ""      "<![CDATA[select cat.name from DomesticCat cat\n"      "where cat.name like 'fri%']]>"msgstr ""#. Tag: programlisting#: query_hql.xml:288#, no-c-formatmsgid "<![CDATA[select cust.name.firstName from Customer as cust]]>"msgstr ""#. Tag: para#: query_hql.xml:290#, no-c-formatmsgid "Queries may return multiple objects and/or properties as an array of type <literal>Object[]</literal>,"msgstr ""#. Tag: programlisting#: query_hql.xml:295#, no-c-formatmsgid ""      "<![CDATA[select mother, offspr, mate.name\n"      "from DomesticCat as mother\n"      "    inner join mother.mate as mate\n"      "    left outer join mother.kittens as offspr]]>"msgstr ""#. Tag: para#: query_hql.xml:297#, no-c-formatmsgid "or as a <literal>List</literal>,"msgstr ""#. Tag: programlisting#: query_hql.xml:301#, no-c-formatmsgid ""      "<![CDATA[select new list(mother, offspr, mate.name)\n"      "from DomesticCat as mother\n"      "    inner join mother.mate as mate\n"      "    left outer join mother.kittens as offspr]]>"msgstr ""#. Tag: para#: query_hql.xml:303#, no-c-formatmsgid "or as an actual typesafe Java object,"msgstr ""#. Tag: programlisting#: query_hql.xml:307#, no-c-formatmsgid ""      "<![CDATA[select new Family(mother, mate, offspr)\n"      "from DomesticCat as mother\n"      "    join mother.mate as mate\n"      "    left join mother.kittens as offspr]]>"msgstr ""#. Tag: para#: query_hql.xml:309#, no-c-formatmsgid "assuming that the class <literal>Family</literal> has an appropriate constructor."msgstr ""#. Tag: para#: query_hql.xml:313#, no-c-formatmsgid "You may assign aliases to selected expressions using <literal>as</literal>:"

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -